Hey guys! I’m making a simple 2d character controller to move around a couple of platforms. It works ok despite the different heights of the jump x), but sometimes when you’re pressing either A or D, it just freezes on the direction you’re moving, and until you move on the opossite direction you can’t move again on that one . Here’s the code :
void FixedUpdate()
{
float movement = Input.GetAxis("Horizontal"); //Take the input of the horizontal axis
if(active)
{
body.velocity = new Vector2(movement * speed, body.velocity.y); //Apply movement and dont change velocity on Y axis
if(Input.GetKeyDown(KeyCode.Space) && grounded)
{
body.AddForce(new Vector2(0, jumpForce), ForceMode2D.Impulse);
grounded = false;
}
}
}
To manage the grounded bool is just a OnCollisionEnter2D with the gameObjects with the tag “Tile”.