- Home /
Zooming out by moving camera away from target(scrollwheel)
Hi, I am making a small space ship simulator and I am trying to add zooming by scrollwheel. So far I got the zooming in right but zooming out doesn't work. This it the code for zooming:
outTarget = transform.localPosition - transform.InverseTransformDirection(new Vector3(0,0,zoomScale));
if(Input.GetAxis("Mouse ScrollWheel") > 0)// && zoom < 2)
{
transform.localPosition = Vector3.ClampMagnitude(transform.localPosition, transform.localPosition.magnitude - zoomScale);
zoom+=1;
}
if(Input.GetAxis("Mouse ScrollWheel") < 0 )//&& zoom > -8)
{
transform.localPosition = outTarget;
zoom -=1;
}
where zoomScale is 3 and zoom is a control value I will use later on to control max and min zoom.
When I scroll down and am looking at the back of the spaceship(initial position of camera) it zooms out corectly but bhen I move the camera left(rotateAround() the target) for about 30 degrees the camera first zooms in rotating slightly to it's initial position and then reaches the above mentioned margin of about 30 degrees and starts to zoom out again.
The script is located on the camera and the target is the center of the ship. The front face of the camera is the positive z axis.
Please help.
Answer by Fr0stbite · Nov 09, 2013 at 11:33 AM
Maybe use fov of the camera: on mousewheel up increase the fov and on down reduce the fiv of cam
I don't want to use FOV because it gives this strange tunnel effect
Your answer
Follow this Question
Related Questions
How to make a smash bros-like camera 3 Answers
Zoom camera based on position between player an object 2 Answers
Camera too zoomed in in built game 1 Answer
Save picture from camera with zoom 0 Answers
How to add Pinch to Zoom? 0 Answers