🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Issues with sprite/animator/animation on my Unity project

Started by
0 comments, last by MuteMist 3 years ago

Hi fellow game designers, currently i´m not working on a established proyect as a whole (yet) but getting to know Unity 2d engine.

I´ve been doing minor adjustments and working on the most basic aspects of a character. Movement, basic movement and making the sprite change while executing those actions.

Ok with the ground settled, the animations on the animator have already been established and the parameters with them.

I did a basic script regarding horizontal movement and jump.

The next step was adding an animator function to that script, i tried replicating a Brackeys tutorial regarding the animation on Unity.

However for some reason, adding that animator function made null the movement functions.

Any suggestions? (I´ll leave the code) and i´m totally open to remaking the script or looking at tutorials/documentation.

public class Character2DController : MonoBehaviour
{
    public float _speed = 2f;
    public float JumpForce = 1f;

    private Rigidbody2D _rigidbody;

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

    void Update()
    {

        
        var _move = Input.GetAxis("Horizontal");
        transform.position = transform.position + new Vector3(_move * _speed * Time.deltaTime, 0, 0);

        if (!Mathf.Approximately(0, _move))
            transform.rotation = _move > 0 ? Quaternion.Euler(0, 180, 0) : Quaternion.identity; 

        if (Input.GetButtonDown("Jump") && Mathf.Abs(_rigidbody.velocity.y) < 0.001f)
        {
            _rigidbody.AddForce(new Vector2(0, JumpForce), ForceMode2D.Impulse);
        }
    }
}

Thank you in advice!

This topic is closed to new replies.

Advertisement