Hi all,
I have an issue which is driving me crazy. I’m a total novice at Unity and I’m trying to create a 2D platformer. I started with a prototype of the mechanics, so no art.
My player is a square with following colliders (This combination of circle and box collider was recommended by a couple of articles):
Slippery is a material with 0 friction and 0 bounciness.
The ground below the player is one long box collider with Slippery material and no Rigidbody2D.
The script behind the player moves the player left/right when pressing left/right by setting the velocity of the rigidbody something like this:
_rigidbody.velocity = new Vector2D( moveSpeed, _rigidbody.velocity .y )
I did not want to use .AddForce(force) because I want my player to stop immediately when he no longer presses left/right. This is done by setting velocity.x to 0 when not having left or right pressed.
The player can jump. This is implemented with:
_rigidbody.AddForce( new Vector2(0, jumpForce) )
When I simply jump there is no bounce when the player lands, just as intended. The problem is when the player is running, jumps while running, then he lands and he has a little bounce. I had the exact same issue in an infinite runner I made. I have tried following things:
- Set collision detection on player’s rigidbody to continuous
- Set Angular Drag on player to 0
- Set Angular Drag on player to 1000000
- Setting velocity.y to 0 when player collides with the ground by using OnCollisionEnter2D()
Feel free to let me know if I need to provide any more information.
EDIT: I can not recreate the bouncing effect by letting the player drop from very high (by setting the y positon in the transform directly) or by letting him jump very high (AddForce()) and fall back down to the ground. The bouncing does occur when I allow the player to move vertically as if having a jetpack (by setting _rigidbody.velocity) and then dropping back to the ground. The cause seems to be very related with changing the velocity on the rigidbody directly.