- Home /
the run animation dont stops if i stop my charaster,hello, i cant stop the "run" animation, when speed == 0
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Move1 : MonoBehaviour
{
float speed = 5.0f;
Rigidbody2D rb;
bool FacingRight = true;
int directionInput;
public bool ground = false;
public float jumpForce = 100f;
Animator animator;
void Start()
{
rb = GetComponent<Rigidbody2D>();
animator = GetComponent<Animator>();
}
void FixedUpdate()
{
rb.velocity = new Vector2(speed * directionInput, rb.velocity.y);
if (directionInput<0 && FacingRight)
{
Flip();
}
else if (directionInput > 0 && !FacingRight)
{
Flip();
}
}
public void Move(int InputAxis)
{
directionInput = InputAxis;
if (speed == 0.0f)
{
animator.SetBool("Run", false);
}
else
{
animator.SetBool("Run", true);
}
}
void Flip()
{
FacingRight = !FacingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
public void Jump()
{
if (ground == true)
rb.AddForce(Vector2.up * jumpForce);
animator.SetTrigger("Jump");
}
}
,my charaster dont stops running if he stopped heres my code
Comment
Best Answer
Answer by Alexx019 · Aug 03, 2021 at 04:23 PM
it seems like you dont call you Move() method anywhere in your FixedUpdate. Because all you are doing now is setting the rigidbodys velocity in your update: (line: 23 rb.velocity = new Vector2(speed * directionInput, rb.velocity.y);)
, and nothing else
Your answer
Follow this Question
Related Questions
Triggering a Player Hit Animation 2 Answers
Can I make animations snap to a frame? 1 Answer
mecanim keep feet planted 0 Answers
Have random.range anims access float speed variable 0 Answers
if condition not working 2 Answers