No Gravity Physics Collisions

So I have a game where I am trying to get dynamic bodies to collide with each other. I tried doing it with kinematic bodies, but this didn’t work because kinematics can’t collide with other kinematics. Because of this, I had to do the workaround where I set gravity to 0.

The problem is, I want certain bodies to not move once another body collides with it.

Example: A ball hits a platform. The platform shifts slightly, even if I set the density of the ball to a very small value and the density of the platform to a very high value. I tried doing a timer within the collision to reset the position of the platform after the collision is done, but it doesn’t quite work as expected.

Anyone know of anything that might help me?

Cheers,
Cowell [import]uid: 52208 topic_id: 11504 reply_id: 311504[/import]

if you don’t want the platform to move, then set it as “static” should do the trick [import]uid: 49842 topic_id: 11504 reply_id: 41714[/import]

Oh - I don’t know why I failed to mention this before. I actually do want the platform to move :slight_smile:

I don’t want it to move from collisions, but I do want it to move onTouch. So, it has an event that will move a little ways upon the touch ended. Hence why I had it set to dynamic.

Sorry for not clarifying it :frowning: [import]uid: 52208 topic_id: 11504 reply_id: 41822[/import]

you can move static object on touch. [import]uid: 48521 topic_id: 11504 reply_id: 41823[/import]

Hmm… still confused as to the situation and desired behavior…

Why can’t you set the platform to kinematic while the ball is dynamic. Collisions will register, the platform can move onTouch, but will not move on collision.

Not sure if this answers the question. Also, keep in mind that an objects physical state (static, kin, dynamic…) can be changed using a function on collision. Might that work for you?

Jeff [import]uid: 18951 topic_id: 11504 reply_id: 41824[/import]

eieiosoftware - you are partially wrong there. Kinematic object don’t collide with any other object. [import]uid: 48521 topic_id: 11504 reply_id: 41826[/import]

You’re right, I was thinking static. [import]uid: 18951 topic_id: 11504 reply_id: 41827[/import]

chimnay, you say I can move statics onTouch? I’m trying to use setLinearVelocity and the platform won’t move.

Eieio, how might I change the physical state? Should i remove the physical body and re-add it? [import]uid: 52208 topic_id: 11504 reply_id: 41843[/import]

why are you using setLinearVelocity to move on touch? Can you post your code for touch movement? [import]uid: 48521 topic_id: 11504 reply_id: 41845[/import]

As far as I know, the best way to change it’s physical type is through a function. I don’t have a simple example in any of my code, but I use it a lot. Here’s a quick example, but it’s not gonna be tested, so might need tweaking:

  
local ball = display.newImage( "ball.png" )  
physics.addBody( ball, { density=5.0, radius = 12 } )  
localGroup:insert( ball )  
  
-- initial body type is "static"  
  
local function resetBall()  
 ball.bodyType = "static"  
 ball.x = 30  
 ball.y = 140  
  
end  
  
resetBall()  
  
local function dropBall ( event )  
  
 ball.bodyType = "dynamic" --body type becomes "dynamic"  
  
end  
  
ball:addEventListener("tap", dropBall) --this happens by tapping the ball  
  

This should work, like I said, I use this type of function often. To move the ball back, you could call the resetBall(). Hope this helps!

Jeff [import]uid: 18951 topic_id: 11504 reply_id: 41893[/import]

chimnay, here’s the code I use for my touch. It’s really not much just yet, and I mainly use it just so I can mess around with the speed in an easy way. Should I use transitionTo?
[lua]function shootPlatform (event )
if event.phase == “ended” then
event.target:setLinearVelocity(vy, currentVySpeed)
end
end[/lua]

eieio, that looks pretty great. I didn’t realize you could change body types like that on the fly, I will have to give that a try when I get off work. :slight_smile: [import]uid: 52208 topic_id: 11504 reply_id: 41902[/import]

Well eieio, your suggestion worked flawlessly. I simply changed the bodyType from static to dynamic at the beginning of the touch event. For some reason I thought you couldn’t change bodies like that within events.

Cheers!
Cowell [import]uid: 52208 topic_id: 11504 reply_id: 42029[/import]