My 2d character is bouncy when landed on the ground. It doesn’t look natural at all.
It has Rigidbody2d attached and a Box collider. Also the code that I use to move character is: rigidbody2d.velocity
Is it has something to do with box collider or rigidbody2d? I have try changing a lot of option in rigidbody2d component such as Mass and Gravity but still the player is bouncing like he is has a ball.
Rigidbodies will not bounce unless they have a physics material or have a force added in code. Can you share the code that you’re using to move your character?
Can you show me your Rigidbody2D and Collider2D settings? Also, can you show me the code that handles the jump velocity?
While there’s a bit of nonsense in your Update function, the movement code looks fine.
Just a tip though, if you want to make your life easier working with physics, you should let the physics system determine your velocity, and use “_myRigidbody.AddForce(deltaX, ForceMode2D.Impulse);” instead of setting the velocity directly. Then your Rigidbody2D’s drag property will slow your character down.
You’ve probably got the Rigidbody2D collision detection mode set to discrete. This means its colliders can overlap other colliders slightly (more the faster it goes) and then the physics system solves the overlap by moving it out. Sounds like this might be what you’re seeing and describing it as a bounce (which it technically isn’t as it doesn’t bounce away from the surface, only from an overlap).
If this is what you’re seeing, then you can use Continuous collision detection instead which is more expensive but stops overlaps and collision tunneling.
AddForce only feels like a mario game if you make it that way. If you set your Rigidbody2D’s drag value, you can make your character’s movement as slidey or stiff as you like. The reason it’s easier is because all the forces are combined and you get a resulting velocity rather than having to do all of that yourself, potentially fighting against the physics system by setting the velocity every frame.
I have a lot of problem with AddForce. I know it has something to do with drag, mass and gravity. I still prefer velocity because it simple except it can’t do a slicey movement or cool jump like AddForce.
I like to use a combination of the two. I generally use AddForce for almost everything, but I still set velocity to 0 sometimes or clamp the velocity manually when I need to.
You can actually achieve the same thing using your own calculations, like if you wanted a slidey feel you could make your movement keys add an acceleration to your velocity delta each frame, and letting go would be subtracting for deceleration, rather than setting the velocity instantly on key press and release.
In the end it does come down to personal preference, but it’s best to fully understand the options at hand before deciding.