How to make camera follow player from point to point
I'm trying to write a script that follows the camera to different areas in the game but while it is in that area the camera is stationary.
public Transform target; public float smoothing = 2f;
Vector3 offset; /
// Use this for initialization
void Start () {
offset = transform.position - target.transform.position;
}
void FixedUpdate (){
Vector3 targetCamPos = target.position + offset;
transform.position = Vector3.Lerp (transform.position, targetCamPos, smoothing * Time.deltaTime);
}
I want to make it smoothly transition between the 2 points and Smoothing * time.deltatime takes care of that but its keeping the camera still while the character is in the area that im having trouble with
Also pause the character movement until the camera reaches its position
Do you have any suggestions?
Answer by ArturoSR · Sep 08, 2016 at 08:01 PM
Hello there.
OK, you need to store the position point, then, after has been moved check if the camera position is the same as the desired point, your function still try to move it because there is nothing to tells it to not keep doing it, so, this way you can control more precisely the behavior of your camera, even you can add some interruption if your character changes his destination at certain event, cheers.
Answer by SoraMahiro · Sep 08, 2016 at 10:07 PM
I dunno if this helps, but what I did for a camera follow was I paired a camera to the player and set it for a display(for you this would depend on if the camera following is the main feed, if so check the display on the camera to 1) and then created a second camera, being the "Main camera" and set it to display 2. Also with the camera on player, turn off its audio listener or unity will complain about there being two audio listeners in the same scene. So what this did was allowed me to have a camera following my character and displaying in the game view, while having a secondary "Main camera" that picked up audio and could be used for a loading screen or a level over GUI, or a death GUI. It will also be smooth as long as your character motion is smooth.
Your answer
Follow this Question
Related Questions
My camera is not smoothly following my character 1 Answer
How to have your player controls change while your camera rotates? 0 Answers
I build a own game but i have a cam problem 0 Answers
Camera flickers while chasing the player 0 Answers
Making a Smooth camera zoom with transform.Translate 1 Answer