Hi all,
I’m currently creating a 2D platformer game. The walking movement speed and jump height are what they should be however the gravity and physics seem a bit off. I don’t want my character moving faster in the air than when walking and i dont want the character to slide when it lands after a jump (when it was moving in the air). What are the right settings for gravity and physics materials to make the game go smoothly, and if that’s not what I should be adjusting what is?
I leave gravity and physics settings at their defaults. In terms of consistent walking speed and jumping speed I use the following variable weights:
For walking, I use this within FixedUpdate()…
if(!playerJumping){
rigidbody2D.velocity = new Vector2(0.8f, rigidbody2D.velocity.y);
}
When the player jumps I set playerJumping=true, and then I wait for a collision event which tells me that the player has ended the jumping routine and then I set playerJumping=false. Then that walking code is executed again (and prevents the player from sliding after landing the jump).
By the way for jumping I use this…
Using the physics engine for platformers is pretty tricky. If you are going for very precise movement and input response (like older platformers) I would look into writing a custom character controller and use raycasting for collision checks.
Here are a couple tutorials to give you an idea of what I mean
This is also very useful for polishing up the way your character controls…