How to get rid of unwanted bouncing

Hi all,

I am developing a game in which a player can move in a world filled with platforms (static rectangular objects). When a player collides with a platform i want to zero player’s velocity vector component which is perpendicular to the platform (so it ‘sticks’ to the platform and moves along it), but to preserve player’s velocity vector component which is tangential to the platform.

That sounds like what setting bounce = 0 for both player and platforms should do. However, every time the player collides with a platform, there is a bounce, which is usually small, but occasionally the player’s speed after the collision looks like it’s several times greater than it was before.

Here is some code, although it’s pretty straightforward:

physics.start() physics.setAverageCollisionPositions(true) physics.setGravity(0, 0) physics.setVelocityIterations(8) physics.setPositionIterations(8) player = display.newCircle(groups.default, x, y, 5) physics.addBody(player, 'dynamic', { density = 1, friction = 0, bounce = 0 }) player.linearDamping = 1 player.angularDamping = 1 platform = display.newRect(groups.default, X, Y, W, H) physics.addBody(platform, 'static', { density = 0, friction = 0, bounce = 0 })

I tried tweaking density, friction and bounce parameters, as well as player’s linear and angular damping, and I can’t reach a good result. 

I also tried setting player’s speed to zero in a collision listener function, but that doesn’t do exactly what I want, because: 1) I want to keep player’s tangential velocity, and 2) even when player stops after collision, it doesn’t stick to the platform, there’s always a small distance between the player and a platform as if the player bounces a little bit after the collision and only then stops.

I could certainly live with a small amount of bouncing, but the situation when player’s speed actually increases after a collision is a bit annoying.

Does anyone have any recommendations on this?

Thanks:) 

I solved this one, but now I got another problem :slight_smile:

Referer to:

http://forums.coronalabs.com/topic/51486-object-moving-at-constant-speed-manually-increase-speed/

http://forums.coronalabs.com/topic/52605-strange-behaviour-when-changing-velocity/

Daniel

and the answer is…

To move an object at constant velocity and avoid velocity change after colision:

[lua]

– Set zero gravity

physics.setGravity(0, 0)

– Add dynamic body with 100% bounce and zero friction

physics.addBody( ball.object, { density=0, friction=0, bounce=1, radius=ball.size } )

– Add static bodies with 100% bounce and 100% friction

physics.addBody( line, “static”, { friction=1, bounce=1 } )

– Move object by applying a linear impulse

local vx, vy = collision.ball.object:getLinearVelocity()

local impulseX = (vx * collision.ball.increaseSpeedFactor / collision.ball.multiplyScore) * collision.ball.object.mass

local impulseY = (vy * collision.ball.increaseSpeedFactor / collision.ball.multiplyScore ) * collision.ball.object.mass

collision.ball.object:applyLinearImpulse( impulseX, impulseY, collision.ball.object.x, collision.ball.object.y )

[/lua]

Daniel

thanks!

I solved this one, but now I got another problem :slight_smile:

Referer to:

http://forums.coronalabs.com/topic/51486-object-moving-at-constant-speed-manually-increase-speed/

http://forums.coronalabs.com/topic/52605-strange-behaviour-when-changing-velocity/

Daniel

and the answer is…

To move an object at constant velocity and avoid velocity change after colision:

[lua]

– Set zero gravity

physics.setGravity(0, 0)

– Add dynamic body with 100% bounce and zero friction

physics.addBody( ball.object, { density=0, friction=0, bounce=1, radius=ball.size } )

– Add static bodies with 100% bounce and 100% friction

physics.addBody( line, “static”, { friction=1, bounce=1 } )

– Move object by applying a linear impulse

local vx, vy = collision.ball.object:getLinearVelocity()

local impulseX = (vx * collision.ball.increaseSpeedFactor / collision.ball.multiplyScore) * collision.ball.object.mass

local impulseY = (vy * collision.ball.increaseSpeedFactor / collision.ball.multiplyScore ) * collision.ball.object.mass

collision.ball.object:applyLinearImpulse( impulseX, impulseY, collision.ball.object.x, collision.ball.object.y )

[/lua]

Daniel

thanks!