- Home /
Question by
Dank_Asuka · Jan 27 at 02:01 AM ·
cameracamera-movementcamera-lookcamera rotation
Getting the camera to move in the direction its facing.
Hello, I am currently experiencing issues trying to get the camera to move in the directions its facing when you rotate the camera. Been trying to figure it out for a while but its still locked into one movement direction.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class CameraController : MonoBehaviour {
public Vector3 pos1;
public Vector3 pos2;
public float xAngle, yAngle, zAngle;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.UpArrow))
{
//Detect when the up arrow key is pressed down
transform.position += pos1;
Debug.Log(transform.position);
Debug.Log("Up Arrow key was pressed.");
}
if (Input.GetKeyDown(KeyCode.DownArrow))
{
//Detect when the up arrow key has been released
transform.position -= pos2;
Debug.Log(transform.position);
Debug.Log("Down Arrow key was released.");
}
if (Input.GetKeyDown(KeyCode.LeftArrow)) { transform.Rotate(xAngle, yAngle, zAngle, Space.Self);
//Detect when the left arrow key has been released
Debug.Log("Left Arrow key was released.");
}
if (Input.GetKeyDown(KeyCode.RightArrow))
{
transform.Rotate(xAngle, -yAngle, zAngle, Space.Self);
//Detect when the left arrow key has been released
Debug.Log("Right Arrow key was released.");
}
}
}
Comment