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
0
Question by thenachotech1113 · Jan 29, 2015 at 02:36 AM · rotationlookcalculateat

make an object "Look at" an other object

Hello everyone, as a part of a game i would like to include a turret that should aim to a vector 3 point, I don´t use the "Look At" script with unity because I would like to add some other parameters but most importantly for learning purposes. Anyway the script i wrote seems to not be working properly, i´ve given it several diferent positions and in most i get two errors saying the following: "!CompareApproximately (SqrMagnitude (q), 1.0F) UnityEngine.Transform:set_eulerAngles(Vector3)" and "transform.rotation assign attempt for 'Turret_81' is not valid. Input rotation is { NaN, NaN, NaN, NaN }." I dont realy understand why, Here is the code im using

         float relativeDistX = point.x - transform.position.x;
         float relativeDistY = point.y - transform.position.y;
         float relativeDistZ = point.z - transform.position.z;
 
         Vector3 eulerRot = Vector3.zero;
 
         eulerRot.x = Mathf.Atan(Mathf.Sqrt(Mathf.Pow(relativeDistX, 2) + Mathf.Pow(relativeDistZ, 2)) / relativeDistY);
         eulerRot.y = Mathf.Atan(relativeDistZ / relativeDistX);
         print ("rot" + eulerRot);
         clone.transform.eulerAngles = eulerRot;


this is just the way i could think of doing it but if you have a better option please tell me. Thank you all.

p.s the reason the error says "Turret_81" its because it creates the turrets and names in runtime them but that is also weird since there is only one turret.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by TheShadyColombian · Jan 29, 2015 at 02:38 AM

Use "lookAt" (how conveniently named :D)

Comment
Add comment · Show 4 · 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 thenachotech1113 · Jan 29, 2015 at 03:17 AM 0
Share

oh thank you very much, i had not thought about that, but i do want to add diferent parameters, such as an x and y rotation cap and a speed. So i think ill use the other way but I very much apreciate your answer!

avatar image TheShadyColombian · Jan 29, 2015 at 03:19 AM 1
Share

Alright. Hope I helped you at least a little :)

avatar image thenachotech1113 · Jan 29, 2015 at 03:55 AM 0
Share

oh certainly, perhaps not on this particular script but certainly learning or remembering stuff always opens a whole variety of options in the project. Cant be more greatful for people like you that put time and effort to apport knowledge to the community.

avatar image TheShadyColombian · Jan 29, 2015 at 04:02 AM 0
Share

Thanks! Good to know

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

20 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Sphere rotation based on object on the sphere 0 Answers

How do you calculate the rotation of a hexagon based on the six Vector3 points 0 Answers

How to make 90 degree snapping camera, center on object? 0 Answers

restrict mouselook X movement script does not work 4 Answers

Limiting Rotation x of Main 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