- Home /
Question by
stoneproductions · Jan 11, 2015 at 06:03 PM ·
2d2d gamelookatjitter
2d look at workaround creates jitter
Hello, I am creating a 2D shooter game and I want the weapon to look at the mouse for aiming.
void Update ()
{
Quaternion rotation = Quaternion.LookRotation (Camera.main.ScreenToWorldPoint(Input.mousePosition) - this.transform.position , transform.TransformDirection (Vector3.up));
transform.rotation = new Quaternion (0, 0, rotation.z, rotation.w);
}
The problem I have now is that the weapon jitters and splits up in a weird way when I aim to a place that is too close to my player.
Thanks for your help!
Comment
This is not how Quaternions work, please look at transform.eulerAngles and Quaternion.Euler in the documentation.
Your answer
Follow this Question
Related Questions
Looking at target in 2D 1 Answer
2d Lighting - Weird light triangles 0 Answers
2D going through walls bug 1 Answer
Changing the orthographicSize of the camera to make sure play field fits 0 Answers
Controller Button Issues 0 Answers