So, I’m wondering what to do for a code like this in C#:
using System.Collections;
public class Movement : MonoBehaviour {
public float speed = 0.45f;
public float turnSpeed = 20f;
// Update is called once per frame
void Update () {
if (Input.GetKey(KeyCode.UpArrow)){
animation.CrossFade ("Walk");
transform.position += transform.forward * speed;
}
else if (Input.GetKey(KeyCode.RightArrow)){
animation.CrossFade ("Walk");
transform.Rotate(Vector3.up * turnSpeed);
}
else if (Input.GetKey(KeyCode.LeftArrow)){
animation.CrossFade ("Walk");
transform.Rotate(Vector3.down * turnSpeed);
}
else{
animation.CrossFade("Idle");
}
}
}
So what do I do if I want to combine the movements of the rotations and the forward transform.position? For example, when I press the up arrow, the character walks forward, and when I press one of the right/left arrows the character turns around, however if I press the up arrow and the left/right arrows at the same time, only one happens (it either turns in place or walks forward)
So my question is, how do I code it so the character can walk forward while turning, and later walk backwards while turning, doing both at the same time without having to continuously just press the side arrows and the up arrows separately? This is so I can have smoother controls, obviously.
Thanks for reading!