Hello,i want to rotate the player y with a/d.
But its super buggy. Moving forward works but if i rotate 90° moving forward doesnt work anymore.
It also looks kind of bad,is there any way to fix it?
(Gif should explain all)
Code :
using UnityEngine;
using System.Collections;
public class player : MonoBehaviour {
public Animator anim;
public Rigidbody rbody;
private float inputH;
private float inputV;
public float RotateSpeed = 100f;
// Use this for initialization
void Start () {
anim = GetComponent<Animator> ();
rbody = GetComponent<Rigidbody> ();
}
// Update is called once per frame
void Update () {
inputH = Input.GetAxis ("Horizontal");
inputV = Input.GetAxis ("Vertical");
anim.SetFloat ("inputH", inputH);
anim.SetFloat ("inputV", inputV);
float moveX = inputH * 20f * Time.deltaTime;
float moveZ = inputV * 50f * Time.deltaTime;
rbody.velocity = new Vector3 (moveX, 0f, moveZ);
if (Input.GetKey(KeyCode.A))
transform.Rotate(-Vector3.up * RotateSpeed * Time.deltaTime);
else if (Input.GetKey(KeyCode.D))
transform.Rotate(Vector3.up * RotateSpeed * Time.deltaTime);
}
}