- Home /
Please help with Mouse aim?
I am trying to make my Camera follow the Sphere with Mouse Aim, it follows the ball but i think that the orientation is changing so the camera is flipping sides. Im still quite a Noob, sorry guys. All I would like for it so do is to follow the ball and allow me to use the mouse to control it.
Here is my code for the Camera
public class MouseAimCamera : MonoBehaviour { public GameObject target; public float rotateSpeed; Vector3 offset; void Start () { offset = target.transform.position - transform.position; } void LateUpdate () { float horizontal = Input.GetAxis ("Mouse X") * rotateSpeed; target.transform.Rotate (0, horizontal, 0); float desiredAngle = target.transform.eulerAngles.y; Quaternion rotation = Quaternion.Euler (0.0f, desiredAngle, 0.0f); transform.position = target.transform.position - (rotation * offset); transform.LookAt (target.transform); } }
Your answer
Follow this Question
Related Questions
2D 360 degress platformer example needed 0 Answers
Calculating a projectiles angle required to hit object. 2 Answers
Is there a way to automatically make physics collider frictionless on sides but not on top? 2 Answers
Collider Movement Script and Physics.Simulate FPS Drop 1 Answer
Making a pendulum? 3 Answers