0
\$\begingroup\$

I am trying to set my character up to strafe left and right and have 2 different animations, on for left and one for right, so far what i have written allows me to strafe left or right but it only ever plays the right strafe animation. What am i doing wrong?

private void Strafe() {
    if (Mathf.Abs (Input.GetAxis ("Strafe")) > 0) {
        animation.CrossFade ("strafeRight");
        _controller.SimpleMove(_myTransform.TransformDirection(Vector3.right) * Input.GetAxis ("Strafe") * strafeSpeed);
    } else if (Mathf.Abs (Input.GetAxis ("Strafe")) < 0) {
        animation.CrossFade ("strafeLeft");
        _controller.SimpleMove(_myTransform.TransformDirection(Vector3.right) * Input.GetAxis ("Strafe") * strafeSpeed);
    }
}
\$\endgroup\$
1
\$\begingroup\$

Right after i posted this i realized i was using MathF.Abs... No Need for that lol. here is correct code and works fine now!

private void Strafe() {
    if ((Input.GetAxis ("Strafe")) > 0) {
        animation.CrossFade ("strafeRight");
        _controller.SimpleMove(_myTransform.TransformDirection(Vector3.right) * Input.GetAxis ("Strafe") * strafeSpeed);
    } else if ((Input.GetAxis ("Strafe")) < 0) {
        animation.CrossFade ("strafeLeft");
        _controller.SimpleMove(_myTransform.TransformDirection(Vector3.right) * Input.GetAxis ("Strafe") * strafeSpeed);
    }
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.