EDIT I NOW HAVE ONE SCRIPT sorry about that. I figured out how to combine the two.
all i want is that whenever i press left or right my character turns in that direction instead of strafing as he does. can anyone please help?
public float speed = 6.0F;
public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
private Vector3 moveDirection = Vector3.zero;
private Animation anim;
private CharacterController controller;
void Awake() {
anim = GetComponent<Animation>();
controller = GetComponent<CharacterController>();
}
void Update() {
CharacterController controller = GetComponent<CharacterController>();
if (controller.isGrounded) {
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton("Jump"))
moveDirection.y = jumpSpeed;
if (Input.GetKey(KeyCode.Q)) {
if (controller.isGrounded)
anim.CrossFade("walk");
transform.Rotate(0, -speed, 0);
}
if (Input.GetKey(KeyCode.D)) {
if (controller.isGrounded)
anim.CrossFade("walk");
}
if (Input.GetKey(KeyCode.A)) {
if (controller.isGrounded)
anim.CrossFade("walk");
}
if (Input.GetKey(KeyCode.E)) {
if (controller.isGrounded)
anim.CrossFade("walk");
transform.Rotate(0, speed, 0);
}
if (Input.GetKey(KeyCode.W)) {
if (controller.isGrounded)
anim.CrossFade("walk");
}
if (Input.GetKey (KeyCode.S)) {
if (controller.isGrounded)
anim.CrossFade("walk");
}
if (Input.GetKey (KeyCode.Space)) {
if (!controller.isGrounded)
anim.CrossFade("jump");
}
{
if(Input.anyKey == false)
if (controller.isGrounded)
anim.CrossFade("idle");
}
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
}