Fixed Angles Camera System Part 1
Switching between camera angles based on player movement
In this article we will make the camera switch angles depending on where our player is moving.
Camera Switch Triggers
Here are our Camera switch triggers (box colliders, Is Trigger checked). When the Player passes through them we want to change the Main Camera position to another fixed position.
Make sure to have a collider and a rigidbody component on your Player and Is Trigger s checked.
This will allow us to detect if our Player has moved through a certain point on the map.
CameraTrigger Script
We put this script on each of our camera triggers. Then we assigned a empty game object that contains the position and rotation of our camera angles to each.
//handle
[SerializeField] private GameObject _targetCamera;
private void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
Camera.main.transform.position = _targetCamera.transform.position;
Camera.main.transform.rotation = _targetCamera.transform.rotation;
}
}
Result
The Player is sometimes poorly visibly, so that’s something to work on next.