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:)