Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Jadebones · Mar 15, 2013 at 08:23 AM · gameobjectsceneviewgame viewgamecontroller

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:

alt text

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.

screenshot (1).png (136.8 kB)
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jadebones · Mar 15, 2013 at 09:20 AM 0
Share

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.

avatar image deltamish · Mar 15, 2013 at 09:22 AM 0
Share

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jadebones · Mar 15, 2013 at 10:00 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Changing a variable across multiple instances of a GameObject 1 Answer

C# Check If Gameobject is within Collider 1 Answer

Using Scripts in AssetBundles 0 Answers

Using the accelerometer to rotate Camera 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges