Body moves sideways as well as up and down.

Hi all, my problem is that, I have an Image 1 colliding with another image 2. When the two collide, image 1 bounces back up, as it should, but after a few bounces, very slowly, image 1 bounces off to the right. Eventually, it bounces right off the image 2 it is colliding with and goes off the screen… I have my gravity set to 0 on the x axis and 10 on the y axis. Here is my code where I set up the two images (bodies), and where I have the collision. Please tell me of any errors. Thank you ! 

local blak=display.newImageRect("assets/@\_blak.png",35,37) blak.x=centerX-50 blak.y=centerY+100 local platm=display.newImageRect("assets/plat.png",140,31) platm.x=centerX-70 platm.y=centerY+250 blak.bodyType = "dynamic" physics.addBody( blak, { bounce=0, friction=.5} ) physics.addBody( platm, "static", { friction=.5, bounce=1 } )

Can I assume that you want one object to bounce continuously, vertically and only at the one location without going anywhere else, on a fixed platform?

The problem with this is that your bouncing object will always defer from it’s initial position because of the variances of the physics engine. It is emulating real objects which are not controlled.

You could use either a piston joint to keep the bouncing object on the same vertical line or you could use a touch joint to continually nudge the object (or even control the object) into position.

That is what I needed. Thank you horacebury :slight_smile:

Hi @Liimbix,

Yes, @horacebury is correct. Also, if the bouncing object doesn’t need to rotate in any way (meaning, it can continue to be oriented vertically upward), you could try setting “.isFixedRotation=true” on it, to help prevent some minor variances in the physics engine collision reactions.

Brent

Can I assume that you want one object to bounce continuously, vertically and only at the one location without going anywhere else, on a fixed platform?

The problem with this is that your bouncing object will always defer from it’s initial position because of the variances of the physics engine. It is emulating real objects which are not controlled.

You could use either a piston joint to keep the bouncing object on the same vertical line or you could use a touch joint to continually nudge the object (or even control the object) into position.

That is what I needed. Thank you horacebury :slight_smile:

Hi @Liimbix,

Yes, @horacebury is correct. Also, if the bouncing object doesn’t need to rotate in any way (meaning, it can continue to be oriented vertically upward), you could try setting “.isFixedRotation=true” on it, to help prevent some minor variances in the physics engine collision reactions.

Brent