So, long story short I’m just trying to make a simple first-person-shooter for the moment (adding on stuff to actually make it interesting later on, but not worrying about that for now). I’m sure that a similar question must have been asked some time in the past but I honestly have no idea how to search for my problem. I’m using my mouse’s inputs to change the rotation on my camera, and attaching an object for movement. The object’s rotation is made to match the camera’s rotation, and then when WASD keys are pressed the object moves according to transform.forward and transform.right… however, when I rotate the camera to certain angles sideways, the movements get all screwed up.
I’m sorry if my explanation is bad, if you need to test yourself to tell the specifics of it, the only specifications for this scene is a camera and single object. Thankyou in advance for advance for anyone who can/does help out with this script. I’m sure it’s definitely not the most efficient, but I’m just trying to work with what I have.
script for the object
var movespeed:float = 4;
var zecamera:GameObject;
function Start () {
}
function FixedUpdate ()
{
transform.rotation.y = zecamera.transform.rotation.y;
if(Input.GetKey(KeyCode.W))
{
transform.position += transform.forward * movespeed * Time.deltaTime;
}
if(Input.GetKey(KeyCode.D))
{
transform.position += transform.right * movespeed * Time.deltaTime;
}
if(Input.GetKey(KeyCode.A))
{
transform.position += transform.right * -movespeed * Time.deltaTime;
}
if(Input.GetKey(KeyCode.S))
{
transform.position += transform.forward * -movespeed * Time.deltaTime;
}
}
script for the camera
var playerlel:GameObject;
var sensitivityY:float = 1;
var sensitivityX:float = 1;
var movespeed:float = 4;
function Update ()
{
//rotate up/down
transform.eulerAngles.y += Input.GetAxis("Mouse X") * sensitivityY * Time.deltaTime;
//rotate left/right
transform.eulerAngles.x -= Input.GetAxis("Mouse Y") * sensitivityX * Time.deltaTime;
transform.position = playerlel.transform.position;
}