- Home /
Question by
Noteboox · Mar 21, 2018 at 05:49 PM ·
animationrotationmovementmovement script
How can I straighten my character's movement and actions?
I'm relatively new to Unity and 3D animations. I'm using a model I found on Mixamo. This character is supposed to be able to move (of course), stab, and shoot. I haven't finished the latter two but have implemented the animations. For some reason, my character moves at a 10 degree angle when walking, as opposed to just walking straight. The shooting and stabbing animations also have the model shooting or stabbing to the side. I know there's something I'm probably missing. Any way to straighten the character's movement/actions?
Here is my script so far:
using System.Collections;
using UnityEngine;
public class ErikaController : MonoBehaviour {
static Animator anim;
public float speed = 2.0f;
public float rotationSpeed = 75.0f;
// Use this for initialization
void Start () {
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
float translation = Input.GetAxis("Vertical") * speed;
float rotation = Input.GetAxis("Horizontal") * rotationSpeed;
translation *= Time.deltaTime;
rotation *= Time.deltaTime;
transform.Translate(0, 0, translation);
transform.Rotate(0, rotation, 0);
if (translation > 0) { anim.SetBool("walk", true); }
else if (translation < 0) { anim.SetBool("backwards", true); }
else { anim.SetBool("walk", false); anim.SetBool("backwards", false); }
if (Input.GetKeyDown("1"))
{
anim.SetBool("shoot", true);
}
if (Input.GetKeyUp("1"))
{
anim.SetBool("shoot", false);
}
if (Input.GetKeyUp("2"))
{
anim.SetBool("stab", false);
}
if (Input.GetKeyDown("2"))
{
anim.SetBool("stab", true);
}
}
}
Comment
Did you find an answer for this? Or have you given up on it?