- Home /
Question by
MascarellDev · May 09, 2015 at 03:09 PM ·
physicsrigidbody2dphysics2dfreeze
Rigidbody2D freezes
Hi guys! Im having troubles with the Rigidbody2D. I'm doing a simple 2d character controller to move around a couple of platforms. It works ok despite of the different jump heights im working right now, but sometimes I'm pressing A or D and the player just freezes and I can't move on that direction until I move the character to the opposite direction. Can someone help me ?
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;
}
}
}
The code to make the player grounded is a simple collision enter 2d with the gameObjects with the tag "Tile".
Comment