- Home /
LookAtMouse wrong orientation
Hello, I am new to programming and Unity, and have been trying to use the LookAtMouse script. The script itself works as it should, the only problem is that when i Play in editor the orientation of the turret that have the script changes.
I have been searching alot trying to find something similar to this, but witouth any luck.
here are pics to show:
http://skugen.wordpress.com/2013/04/30/lookatmouse-problems-pic-ref/
top left picture shows the ingame orientation of turret, it follows the mouse as it should, but points downwards instead of forward.
top right pic shows the original mesh in prefab.
Bottom pic shows orientation in editor.
It looks like the LookAtMouse script sets the turrets orientation back to its original imported orientation(tried changing orientation in 3ds Max, and tried Z-axis/Y-Axis as up, witouth any changes in the original imported orientations.
Any ideas or pointers to what can cause this and how to fix?
Any help will be much appreciated!
regards, skuGen
Answer by robertbu · Apr 30, 2013 at 06:50 PM
LookAt() scripts almost always point the positive 'Z' side of the object at the position/direction specified. I'm not sure which LookAtMouse script you are talking about. I posted a very simple one awhile ago. In a third-person, 3D, turret-type environment you are likely to need someone more complex.
One solution to your problem is to make your Turret a child of an empty game object.
Rotate your turret to the position orientation you want with the gun barrel pointing to towards positive Z.
Create an empty game object and place it at the pivot point of the turret.
Make the turret a child of the empty game object.
Attach the script to the empty game object.
Answer by skuGen · Apr 30, 2013 at 07:38 PM
Thank you for fast answer robertbu!
I found a solution myself just now, that I did not think of first.
By changing the pivotpoint in 3ds max, I rotated the pivot point to counter the rotation that occured while playing it. with the pivotpoint now changed(Y rotated to become Z in 3ds max) it now faces the way it was intendeed to.
Your answer
![](https://koobas.hobune.stream/wayback/20220613101313im_/https://answers.unity.com/themes/thub/images/avi.jpg)