Question by
CCSwaG · Aug 11, 2020 at 10:16 AM ·
camera-movementcamera rotatecamera follow
How to smooth change to a different camera position when still following the player?,How to smooth change my camera position when still following the player?
For my game, I want to have different perspective of cameras during different stages, I figured out how to move the camera into a second position based on the player position, but how to do that smoothly? For example, in the code, I want to change the camera position from the top and a little behind of the player to the right side of the player.
public class CameraController : MonoBehaviour {
public Transform player;
private Vector3 FirstOffset = new Vector3(0, 10, -10); // First camera position
private Vector3 SecondOffset = new Vector3(-9.5f, -7.3f, -4f); //Second camera position
// Start is called before the first frame update
// Update is called once per frame
void Update()
{
transform.LookAt(player);
transform.position = player.transform.position + FirstOffset;
if(player.position.z > 20){
transform.position = player.transform.position + SecondOffset;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
I want to make the player move in the same direction that the camera moves 0 Answers
getting Jittery movement on camera when player rotating and moving in same time 0 Answers
CineMachine Camera Movement is inverse 1 Answer
When attaching my custom camera script camera shakes when player starts to move fast. 1 Answer