N
N
Nikita Salnikov2020-07-03 11:44:29
C++ / C#
Nikita Salnikov, 2020-07-03 11:44:29

Why is the animated character not moving?

hello. it is not possible to set the elementary movement of the character.
character 2D sprite. ordinary bird. There is also a background and a ground. hung a box collider on the ground. on a rigidbody bird and a collider. made an endless animation of the background and ground through scripts. bird animation works. flaps its wings. but now I want that when you press the keys to the left to the right, the bird also moves, but for some reason it doesn’t work and the character stands still. what is the problem? what am I doing wrong?

public class BirdFlying : MonoBehaviour
{
    public float speed;
    public float jumpForce;
    private float moveInput;
    private Rigidbody2D rb;

    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
    }

    void FixedUpdate()
    {
        moveInput = Input.GetAxis("Horizontal");
        rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zZaKko, 2020-07-03
@nikitasalnikov

Maybe the function is not FixUpdate(), but FixedUpdate()? First check the code, and then go to the forum))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question