Question by
Flyingmedic · May 26, 2017 at 12:28 PM ·
rotationmovementcontrols
when my character rotates the controls of the initial rotation stay and not change with it
i am a beginner coder so i don't know how to this, can anyone help me with this, i want my character when rotated the controls to go with it, like if i rotate right i can press right again and go right and not like it's now; i have to press left to be able to press right again. i need the controls to be switched with the rotation ? i don't know.. anyone understand that ? here's my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playerController : MonoBehaviour {
public float moveSpeed;
void Start ()
{
Cursor.lockState = CursorLockMode.Locked;
}
void Update ()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0, moveVertical);
if (moveHorizontal != 0 || moveVertical != 0)
{
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(movement), 0.15F);
}
transform.Translate(movement * moveSpeed * Time.deltaTime, Space.World);
if (Input.GetKeyDown("escape"))
Cursor.lockState = CursorLockMode.None;
}
}
Comment