RayDart
1
If my character is standing still and is hit by a falling object it starts sliding. Why is this happening and how can I stop it. This is my player movement script:
public void Update()
{
//move left
if (Input.GetKeyDown(KeyCode.LeftArrow))
{
transform.localScale = new Vector2(1, 1f);
}
if (Input.GetKey(KeyCode.LeftArrow))
{
if (xPos > -7)
{
anim.SetBool("IsMoving", true);
transform.position += Vector3.left * Time.deltaTime * moveSpeed;
xPos = transform.position.x;
}
else
{
anim.SetBool("IsMoving", false);
}
}
if (Input.GetKeyUp(KeyCode.LeftArrow))
{
anim.SetBool("IsMoving", false);
}
//move right
if (Input.GetKeyDown(KeyCode.RightArrow))
{
transform.localScale = new Vector2(-1, 1f);
}
if (Input.GetKey(KeyCode.RightArrow))
{
if (xPos < 3)
{
anim.SetBool("IsMoving", true);
transform.position += Vector3.right * Time.deltaTime * moveSpeed;
xPos = transform.position.x;
}
else
{
anim.SetBool("IsMoving", false);
}
}
if (Input.GetKeyUp(KeyCode.RightArrow))
{
anim.SetBool("IsMoving", false);
}
}
If you using Rigidbody or Rigidbody2D trying locking it Constraints Freeze Rotation checkbox.