Reputation: 1703
I am trying to make simple product visualisation. And I want to zoom or move camera towards the object. My code looks like this:
public class mouseMover : MonoBehaviour {
public Transform target;
public float speed;
void Update () {
if (Input.GetAxis ("Mouse ScrollWheel") < 0) {
float scroll = Input.GetAxis ("Mouse ScrollWheel");
transform.LookAt (target);
transform.Translate(0, 0, scroll * speed, Space.World);
}
if (Input.GetAxis ("Mouse ScrollWheel") > 0) {
float scroll = Input.GetAxis ("Mouse ScrollWheel");
transform.LookAt (target);
transform.Translate(0, 0, scroll * speed, Space.World);
}
}
}
But when I try to zoom, it just "fly" around the object and when camera get on the another side of object, it starts to recede.
Upvotes: 1
Views: 4830
Reputation: 7346
It's because you use Space.World instead of Space.Self :
void Update ()
{
float scroll = Input.GetAxis ("Mouse ScrollWheel");
transform.LookAt (target);
transform.Translate(0, 0, scroll * speed, Space.Self);
}
Upvotes: 2