Question by
KOCGI · Aug 30, 2018 at 05:00 AM ·
cameracamera movementmouse position
Mouse Scroll not working on Camera (But can scroll the player)
I want to add mouse scroll to the Camera of my university project. Simply moving the distance from camera and player. I do not want to change the fov, as this would ruin gameplay. Here is the script, not a big deal. But sadly it's not working. Likely I overwrite the position the same time, but I also need the camera to follow the player no matter what else is happening. How can I fix that? Using the main Camera btw.
public class PlayerCamera : MonoBehaviour
{
public float rotateSpeed = 90.0f;
private Transform target;
private Vector3 startOffset;
public float zoomSpeed = 20;
private void Start()
{
target = transform.parent;
startOffset = transform.localPosition;
transform.SetParent(null);
}
private void Update()
{
UpdateCamera();
}
private void UpdateCamera()
{
if (target != null)
{
float scroll = Input.GetAxis("Mouse ScrollWheel");
transform.position += this.transform.forward * scroll * zoomSpeed;
transform.position = target.TransformPoint(startOffset);
transform.rotation = Quaternion.Slerp(transform.rotation, target.rotation,
rotateSpeed * Time.deltaTime);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
I need help with my third person camera raycast 0 Answers
Camera flickers while chasing the player 0 Answers
Is my MonoDeveloped Glitchd ??? 1 Answer
how to read in game objects in a list from different script 1 Answer
Unity 5.2 VR Camera Problem 0 Answers