- Home /
Question by
dvxl · Apr 05, 2020 at 04:56 PM ·
velocitysmoothzoomorthographic camerasmoothdamp
Zoom Out depending on velocity/speed
Hello! I have an orthographic camera that has to zoom out smoothly depending on the velocity of my player. I know that in have to change the camera.main.orthographicSize to zoom out. Can someone make me a script for this or tell me exactly what to do? The zoom should also have a minimum zoom and a maximum zoom. thx for all your answers!
Comment
Answer by BBIT-SOLUTIONS · Apr 05, 2020 at 05:13 PM
Something like this should work, have not tested it, so you maybe have to adapt the values for the variables in the first 4 lines a bit:
float minZoom = 1f;
float maxZoom = 5f;
float zoomStep = 0.1f;
float smoothness = 0.1f
public void ZoomOut(){
StartCoroutine(ZoomOutSmoothly());
}
private IEnumerator ZoomOutSmoothly(){
WaitForSeconds myWait = new WaitForSeconds(smoothness);
Camera.main.orthographicSize = minZoom; //you could also comment this line out and just use your current zoomValue... It's just for having a start position for the zoomanimation
while(Camera.main.orthographicSize < maxZoom){
Camera.main.orthographicSize += zoomStep * velocity; //take your players one for the velocity
yield return myWait;
}
Camera.main.orthographicSize = maxZoom; //ensure it is exactly set to the maxZoom value after the animation
}
Your answer
Follow this Question
Related Questions
Help me with smooth zoom 1 Answer
Camera smooth Zoom in/out (without FieldOfView) 1 Answer
Mathf.SmootDamp not working correctly 1 Answer
Smooth movement using Rigidbody2d 3 Answers
Mouse wheel zoom 1 Answer