Answer the question
In order to leave comments, you need to log in
Why did the character stop walking after adding animations?
Good evening, please help if someone understands. In general, I started working with character animations (I created everything necessary and connected them through the animator, everything seems to be playing), but the problem is that the character stopped walking and jumping (before that everything was in order). I attach the script (I myself I understand that it most likely does not work here due to the fact that both the movement of the character and the launch of animations are attached to anim for me). Of course, I have a whole bunch of errors here, probably
public class PlayerController : MonoBehaviour
{
public float speed;
public float jump;
bool ground;
bool right;
Rigidbody2D rb;
private float moveInput;
private bool isGrounded;
public Transform feetPos;
public float checkRadius;
public LayerMask WhatIsGround;
private Animator anim;
void Start()
{
anim = GetComponent<Animator>();
rb = GetComponent<Rigidbody2D>();
right = true;
}
private void Update()
{
isGrounded = Physics2D.OverlapCircle(feetPos.position, checkRadius, WhatIsGround);
if(isGrounded == true && Input.GetKeyDown(KeyCode.Space))
{
rb.velocity = Vector2.up * jump;
anim.SetTrigger("takeoff");
}
if(isGrounded == true)
{
anim.SetBool("isJumping", false);
}
else
{
anim.SetBool("isJumping", true);
}
if (right == true)
{
transform.localRotation = Quaternion.Euler(0, 0, 0);
}
else if (right == false)
{
transform.localRotation = Quaternion.Euler(0, 180, 0);
}
if (Input.GetKeyDown(KeyCode.D))
{
right = true;
}
else if (Input.GetKeyDown(KeyCode.A))
{
right = false;
}
if (ground == true)
{
if (Input.GetKey(KeyCode.D))
{
anim.SetBool("isRunning", true);
}
else if (Input.GetKey(KeyCode.A))
{
anim.SetBool("isRunning", true);
}
else
{
anim.SetBool("isRunning", false);
}
}
}
private void FixedUpdate()
{
moveInput = Input.GetAxis("Horizontal");
if (moveInput == 0)
{
anim.SetBool("isRun", false);
}
else
{
anim.SetBool("isRun", true);
}
rb.velocity = new Vector2(Input.GetAxis("Horizontal") * speed, rb.velocity.y);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question