Hello. I have an object with a rigid body that can move left and right and jump on platforms. The problem I have is that when the character jumps off a platform and then moves into the platform it gets “stuck” and is unable to fall if the button is held down. What would be the best way to fix this? I figured I need to disable the direction it was moving, but I’m not sure how to do that without breaking the other direction.
The code I currently have is:
// Update is called once per frame
void FixedUpdate () {
Vector3 p = mainCharacter.transform.position;
if (Input.GetKey (KeyCode.A))
{
p.x -= 0.2f;
} else if (Input.GetKey (KeyCode.D))
{
p.x += 0.2f;
}
if (Input.GetKey (KeyCode.Space))
{
if (isJumping == false)
{
mainCharacter.rigidbody.AddForce(Vector3.up * JumpForce);
isJumping = true;
}
}
Debug.Log (mainCharacter.rigidbody.velocity.y.ToString ());
mainCharacter.transform.position = new Vector3(p.x, p.y, 0);
mainCamera.transform.position = new Vector3(p.x, p.y + 2, -10.0f);
}
void OnCollisionEnter(Collision col)
{
if (col.gameObject.tag == "Land")
{
isJumping = false;
}
}