I'm trying to have a camera rotate mirror the player's rotation, however, this isn't happening and the camera isn't rotating at all. Can anyone explain what I'm doing wrong and how to fix it?
public class PlayerActions:MonoBehaviour{
Camera mainCamera;
public Rigidbody player;
public GameObject playerShot;
public Transform shotSpawn;
public Boundary boundary;
public int speed;
public int tilt;
public int bank;
public float fireRate;
private float shotDelay;
void Start(){
mainCamera = Camera.main;
player.GetComponent<Rigidbody>();
}
void FixedUpdate(){
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 move = new Vector3(moveHorizontal, moveVertical, 0f);
player.velocity = move * speed;
player.position = new Vector3(Mathf.Clamp(player.position.x, boundary.xMin, boundary.xMax), Mathf.Clamp(player.position.y, boundary.yMin, boundary.yMax), 0f);
transform.rotation = Quaternion.Euler(0f, 0f, player.velocity.x * -bank);
}
void Update(){
if(Input.GetKey("space") && Time.time > shotDelay){
shotDelay = Time.time + fireRate;
Instantiate(playerShot, shotSpawn.position, shotSpawn.rotation);
}
}
}
As it's working now, the player is rotating, but the camera isn't.
If you notice in the video linked below, the ship is rotating, but if you look at the static asteroid, you'll notice that the camera isn't. Not Rotating Game View Not Rotating Editor View
Inspector