- Home /
When animations play I can't move my player
I never animated in the Unity engine before. Mainly I made games with just shapes but I tried out sprite animation but when the animation plays it locks my player in place and it breaks game physics so my player cant fall. I tried removing the empty game object that checks if it's jumping but it still doesn't work. Here is the code please let me know what I'm doing wrong thank you.
private Rigidbody2D rb;
public float runSpeed;
public float jumpForce;
private float moveInput;
private bool isGrounded;
public Transform feetPos;
public float checkRadius;
public LayerMask whatIsGround;
public float jumpTimeCounter;
public float jumpTime;
public bool isJumping;
private Animator anim;
void Start() {
anim = GetComponent<Animator>();
rb = GetComponent<Rigidbody2D>();
}
void FixedUpdate() {
moveInput = Input.GetAxisRaw("Horizontal");
rb.velocity = new Vector2(moveInput * runSpeed, rb.velocity.y);
}
void Update() {
isGrounded = Physics2D.OverlapCircle(feetPos.position, checkRadius, whatIsGround);
if (isGrounded == true && Input.GetKeyDown(KeyCode.W)) {
isJumping = true;
jumpTimeCounter = jumpTime;
rb.velocity = Vector2.up * jumpForce;
}
if(moveInput > 0) {
transform.eulerAngles = new Vector3(0, 0, 0);
} else if (moveInput < 0) {
transform.eulerAngles = new Vector3(0, 180, 0);
}
if (moveInput < 0) {
anim.SetBool("isRunning", false);
}
else {
anim.SetBool("isRunning", true);
}
if (Input.GetKey(KeyCode.W) && isJumping == true) {
if (jumpTimeCounter > 0)
{
rb.velocity = Vector2.up * jumpForce;
jumpTimeCounter -= Time.deltaTime;
}
else
{
isJumping = false;
}
}
if (Input.GetKeyUp(KeyCode.W)) {
isJumping = false;
}
}
}
Answer by jackmw94 · Nov 08, 2020 at 06:58 PM
Is your animator applying root motion? This could mean that the animations themselves are setting the object's transform.
This is set via a checkbox on the animator component itself.
I have the same problem and after applying root motion it's still not working
if the animation applys root motion that would be the problem - adding root motion is just the wrong way. Removing it could be a possible solution.
In general if you have an issue and need help please open a new question with a detailed explanation of your issue and details on your setup
Answer by NOGOODGAMES · Apr 09 at 01:35 PM
In case anyone stumbles upon this, the best solution is: Create an empty gameobject and parent all your rig's hierarchy and skinned meshes under it -name it animator -copy and paste the animator component from your parent gameobject to the animator gameobject you created
Everything should work fine. The idea is, you don't want to have the logic for movement on the same gameobject as the gameobject where your animator component is attached.
Hope this helps someone!