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 SupremeBashar · Apr 18, 2014 at 06:24 PM · rotationvectoreulerdegrees

Need help in setting a game-object's rotation to euler-degrees.

Hi Guys,

I'm (trying) to make something like a radarsimulator. One radar scans and when it found a target, it hands the targets' vector to the an other script. That other script is supposed to convert the vector to angles and then rotate a game object to face the target. Calculating the angels works out just fine, however, rotating the object to the target doesn't work :-(. Can you guys give me a hand?

Snippet of the code that transforms the vector to degrees and rotates the object:

 Vector3 origin; 
 Vector3 target = new Vector3(0f ,0f ,0f);
 float angleX, angleY, angleZ;

 public void SetToTargetDirection(Vector3 targetFromMultibeam){
 float angleH = 0, angleV = 0;
 
 origin = transform.position;                                                                
 target = -origin + targetFromMultibeam;                                                            
                             
 angleH = Mathf.Atan2(target.z, target.x) * Mathf.Rad2Deg;                                                        
 angleV = Mathf.Atan2(target.y, Mathf.Sqrt((target.x * target.x) + (target.z * target.z))) * Mathf.Rad2Deg;            
         
 deltaH = angleH - transform.rotation.eulerAngles.x;                                            
 deltaV = angleV - transform.rotation.eulerAngles.y;                                                
 transform.Rotate (deltaV, 0, deltaH);
 }
 
Comment
Add comment · Show 5
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 robertbu · Apr 18, 2014 at 06:32 PM 0
Share

I'm away from my desk, so I cannot verify any suggestion I make. As a start try assigning to transform.eulerAngles:

 transform.eulerAngles = new Vectore3(angleV, 0, angleH);

avatar image mostlytigerproof · Apr 19, 2014 at 01:00 AM 1
Share

Is there a particular reason you're converting to polar and setting angles rather than using Transform.LookAt()?

avatar image SupremeBashar · Apr 19, 2014 at 02:38 AM 0
Share

@ mostlytigerproof I'm using polar because I am simulating the radar by generating game-objects (pulses) which start at the transform.position and move in a certain direction. When they collide with a target, their speed is inversed and they return to the transform.position. The tracking radar then has to send a pulse in the direction of the target (old pulse's direction and distance, recalculated to the trackingradar's position).

I know its a bit jibebrisch, but it's hard to discribe :-).

@ robertbu I'll have a go with that co$$anonymous$$g weekend :-)

@ all, thx for all the feedback!

avatar image mostlytigerproof · Apr 19, 2014 at 03:00 AM 0
Share

If I were in your shoes I'd still use direction vectors ins$$anonymous$$d of polar. i.e.

     Quaternion rotation = Quaternion.LookRotation(target - origin);
     transform.rotation = rotation;

If you need more control, you can blend quaternions using slerp or use ToAngleAxis to get back to polar.

avatar image SupremeBashar · Jul 06, 2014 at 08:02 PM 0
Share

@ mostlytigerproof

I think when using Quaternion.LookRotation, you have to look at a game object (i could very well be wrong though). That is not what I'd like to do. I like to rotate the gameobject in such a way it is facing the same direction as the Vector that is calculated. That's why I'm converting to degrees. However, rotating over these degree values isn't working.

0 Replies

· Add your reply
  • Sort: 

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

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

Related Questions

Mimic rotation from a joystick 1 Answer

Is there a way to convert a euler vector from 0 to 360 --> -90 to 90? 0 Answers

Rotation on Android vs. PC 0 Answers

Camera Script Rolling on the Z 3 Answers

Help with gun accuracy in degrees. 3 Answers


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