Good day Master,
I wanted to seek for your advice on what is the best way to make my player, if user is not clicking on him, slow until it stop then it will change the animation from running to idle.
So below is my player control script and i manage to make him run and accelerate everytime player click on him:
Vector3 velocity = Vector3.zero;
public float forwardSpeed = 1f;
bool DoRun = false;
Animator animator;
// Use this for initialization
void Start () {
animator = transform.GetComponentInChildren<Animator>();
if(animator == null) {
Debug.LogError("Didn't find animator!");
}
}
// Update is called once per frame
void Update()
{
Debug.Log (forwardSpeed);
if(Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0) ) {
DoRun = true;
}
}
void FixedUpdate(){
if(DoRun) {
rigidbody2D.AddForce( Vector2.right * forwardSpeed);
animator.SetTrigger("DoRun");
DoRun = false;
}
}
everything is fine but now i cannot slow him down and stop running
I used the line drag in rigidbody2d but i am having hard time setting the trigger animation to idle ![]()
Hoping some kind hearted master will help me
thanks in advance