- Home /
Question by
Censureret · Dec 01, 2020 at 04:48 PM ·
vector3transform.position
Movement script for camera relative to where it looks
So i have the following simple script:
void Update()
{
yaw += RotationSpeed * Input.GetAxis("Mouse X");
pitch -= RotationSpeed * Input.GetAxis("Mouse Y");
transform.position = transform.position +
new Vector3(-EasyInputSource.MovementX * MovementSpeed * Time.deltaTime,
0, -EasyInputSource.MovementY * MovementSpeed * Time.deltaTime);
transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);
}
Where the EasyInputSource is just the same as unity's built in just with some extra features.
Now this works to move the camera however when i rotate the camera 180 degrees and press forward the movement is reversed. This means that the code doesn't work relative to the point I'm looking at.
How can i fix this issue?
Comment