- Home /
How to fix a game objects that changes its position when viewed in game mode?
I have a sentry gun scripted to follow or look at my character. In the scene view the sentry gun rests flat on a surface, but in game view it is turned on its side... Why does this happen and how can I fix it?
The sentry gun is a 3D game object with no rigid body, has mesh renderer, mesh collider, textures and a script to look at target. It will be a simple, stationary AI/enemy character when finished.
Script:
Imagine the sentry gun or game object is attached to a DVD that lays flat on the ground when in scene view, but when you go into game view, that DVD and game object are standing on its side.
Right...sorry...
The sentry gun is a game object, no rigidbody, pretty basic 3D object for learning, has mesh renderer, mesh collider, and texture. Also script to look at target. Will be simple and stationary AI/enemy character when finished.
Script: 1. var LookAtTarget:Transform; 2.
3. function Update () 4. { 5. transform.LookAt(LookAtTarget); 6. } 7.
hi make sure the local axis and world axis of the sentry gun is same if not make it an child of a empty game object and the n attach your script to the sentry gun
Answer by Bunny83 · Mar 15, 2013 at 09:22 AM
LookAt will rotate the object to make it's forward axis (the blue z axis) point towards the target and the up vector (the green y axis) will point upwards. Your object's forward and upward axis must match these or the gun will of course pointing somewhere else.
To fix this, either rotate your gun in your modelling application so it comes in the right way, or use an empty gameobject which will be your actual gun (so attach your script there) and add your model as child. You can rotate the child so it's forward axis will match the parents forwards direction.
Yay! that worked! Thanks so much! And after reading your post I finally found the answer in the unity manual as well.
I still have much to learn... Thanks again, you were a great help. =)
Your answer
![](https://koobas.hobune.stream/wayback/20220613094445im_/https://answers.unity.com/themes/thub/images/avi.jpg)