- Home /
Unity2d: when animations is working , player can't move. (Code is here).
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playercontroller : MonoBehaviour
{
private Rigidbody2D rb;
public float speed;
Animator anim;
public float jumpForce;
private bool aord;
void Start()
{
rb = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
void FixedUpdate()
{
aord = (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.A));
if(Input.GetKey(KeyCode.D))
{
rb.velocity = new Vector2(speed,0);
anim.Play("run");
}
else if(Input.GetKey(KeyCode.A))
{
rb.velocity = new Vector2(-speed,0);
anim.Play("run");
}
else
{
rb.velocity = new Vector2(0,0);
anim.Play("Idle");
}
}
}
Answer by NoahDaNerd · Nov 22, 2020 at 02:23 PM
Your animation probably animates the position. This would override the script. Just remove that and it should work. If you want it to animate the position, then delete the sprite component from your player, add a gameobject as a child to the player, then put the sprite on that. You can animate the child, and move the parent with your script.
Thanks , i just made animation with compression and because of it position is always changing .
Your answer
Follow this Question
Related Questions
Is there a new retargetting system for the animation in 5.5? 1 Answer
[Solvedf]Animator is not playing an AnimatorController 2 Answers
Velocity not changing value in Blend Tree 0 Answers
Animation stuck if i hold the trigger Button 1 Answer
Removing blending between two animations for only certain parameters 1 Answer