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 Chimera3D · Jun 16, 2013 at 12:41 AM · rotationobjectseuleranglesrangepositions

Range of Rotation Based off of Positions

I have two gameobjects, they both stay very close to their original positions but do move a little bit, I want one of them to have a range of eulerAngle values (only on the z axis). The range of eulerAngle values is supposed to be defined by a max and min relative to an angle that is directly aligned with the other object. The max can be the direct angle plus 20 and the min the direct angle plus 30, then I'll have the object keep rotating between these two values. Basically one object keeps another object in a view range I guess but rotates. How can I go about doing this? Specifically finding the direct angle, that's all I really need help with.

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
0
Best Answer

Answer by robertbu · Jun 16, 2013 at 05:54 AM

Since you are only rotating on the 'z' axis and want to keep another object in view, I'm assuming this is a 2D game. You can use Mathf.Atan2() to determine the absolute angle:

 Vector3 v3T = watchee.transform.position - watcher.transform.position;
 float angle = Mathf.Atan2(v3T.y, v3T.x);  
Comment
Add comment · Show 3 · 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 Chimera3D · Jun 17, 2013 at 12:34 AM 0
Share

The code works $$anonymous$$us the fact that the object looks directly downwards, but the rotation part works and everything it's just not looking at the object for some reason. It might be something specific to my code though so I have to look harder.

avatar image robertbu · Jun 17, 2013 at 12:47 AM 1
Share

Note, this will align the right of the object with the angle. So you may need to add or subtract something from the angle calculation if some other side other than right is the looking side.

avatar image Chimera3D · Jun 17, 2013 at 12:57 AM 0
Share

So what I had to end up doing is this:

 var v3t : Vector3 = (target.transform.position - transform.position);
 var rads = $$anonymous$$athf.Atan2(v3t.y, v3t.x)+($$anonymous$$athf.PI/2);
 angle = RadDegConvert(rads);


And then add this function elsewhere in the code and it all worked, thanks!

 function RadDegConvert(radians : float) : float {
     return(radians*360/($$anonymous$$athf.PI*2));
 }

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

14 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

Related Questions

Rotating a rigidbody on mouse click. 1 Answer

Rotation on Android vs. PC 0 Answers

2D animation : problem with rotation interpolation 1 Answer

trying to RotateAround an object around another object using mouse 1 Answer

Trouble applying rotation locally instead of globally -1 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