isse26
January 6, 2014, 1:32pm
1
Hi im trying to make a zooming funktion but when I run this code (see below) it moves the camera in both y and z.
I have tried to make a kinematic rigidbody and lock position in z but that did’nt help
if (Input.GetAxis(“Mouse ScrollWheel”) > 0)
{
Camera.mainCamera.transform.Translate(new Vector3(0, -movespeed * Time.deltaTime, 0));
}
else if (Input.GetAxis(“Mouse ScrollWheel”) < 0)
{
Camera.mainCamera.transform.Translate(new Vector3(0,movespeed * Time.deltaTime,0));
}
I have also tried to use Vector3.up and Vector3.down but that did not help either
Moves the transform in the direction and distance of translation.
If relativeTo is left out or set to Space.Self the movement is applied relative to the transform’s local axes. (the x, y and z axes shown when selecting the object inside the Scene View.) If relativeTo is Space.World the movement is applied relative to the world coordinate system.
I think your issue is the rotation of the transform. I would also try this,
transform.position += Vector3.up * movespeed * Time.deltaTime;
You can also do it with a lerp for a smoother movement.