I have a game where the camera’s rotation is fixed, but i want it to follow the player. However, the player’s rotation changes. I’m having trouble writing a script to account for that. Here’s what I have:
var playerSpeed : float;
var playerChar : GameObject;
function Update () {
//transform.Translate(Vector3(Input.GetAxisRaw(“Horizontal”)Time.deltaTimeplayerSpeed,0,Input.GetAxisRaw(“Vertical”)Time.deltaTimeplayerSpeed));
if(Input.GetAxisRaw(“Horizontal”) != 0 Input.GetAxisRaw(“Vertical”) != 0) {
// transform.Translate(
} else if (Input.GetAxisRaw(“Horizontal”) != 0) {
// transform.Translate(Vector3(Time.deltaTimeplayerSpeed,0,Time.deltaTimeplayerSpeed*
} else if (Input.GetAxisRaw(“Vertical”) != 0) {
transform.Translate(Vector3(Time.deltaTimeplayerSpeedMathf.Sin(playerChar.transform.rotation.yMathf.Deg2Rad),0,Time.deltaTimeplayerSpeedMathf.Cos(playerChar.transform.rotation.yMathf.Deg2Rad)));
}
}
I’m only working with the vertical axis right now for simplicity. Thanks in advance.