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 Crispy · Jul 19, 2012 at 04:59 AM · rotationorbittrigonometry

Need help orbiting an object around another object based on rotation

I have a camera that I want to position upon a player-centric orbit; the position is based upon the camera's current x rotation. The initial x rotation is 0 and the z-offset is -10 (which is also the radius of the orbit sphere). Any help with the trigonometry of this would be appreciated.

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

Answer by Seth-Bergman · Jul 19, 2012 at 05:59 AM

hmm, kind of a tough one.. You want the camera to rotate around the player, always at the same distance, and always facing the player, correct?

If so, using transform.LookAt(playerObject.transform) takes care of the direction.. and transform.RotateAround(playerObject.transform,Vector3.up,speed) should handle the rotation.. I figure if you're always looking at the object, adjusting the distance to 10 should be pretty simple:

 if(Vector3.Distance(transform.position,playerObject.transform.position) > 10)
 //move forward
 else if(Vector3.Distance(transform.position,playerObject.transform.position) < 10)
 //move back

at least that's how I would probably try to go about it, avoiding trig altogether.. There are scripts out there too for this, including the mouseOrbit script in Standard Assets I believe.. search the forums for full examples.. If I mistook your objective, please clarify!

EDIT: My logic is that RotateAround works on a 360 degree rotation, same as rotating the camera.. if I know I want to rotate the camera 55 degrees, the ending position in my rotation around the object to stay facing it is the same reached by rotating around it by 55 degrees.. It wouldn't really matter if I rotate the camera and capture the corresponding position, or vice versa.. (but I may still be missing something in your needs...)

Comment
Add comment · Show 2 · 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 Crispy · Jul 19, 2012 at 06:23 AM 0
Share

Unfortunately, this isn't really what I was looking for. What I want is to be able to supply an angle (e.g. -45/315) and have a calculated position returned. RotateAround doesn't work because that method only increments or decrements the current rotation, rather than setting it.

I was looking for something more like this:

Vector3 targetPos = new Vector3( (cameraTarget.transform.position.x + OffsetX), (cameraTarget.transform.position.y + OffsetY) - ($$anonymous$$athf.Sin(transform.rotation.x) OffsetZ), cameraTarget.transform.position.z - ($$anonymous$$athf.Cos(transform.rotation.x) OffsetZ));

However, this doesn't exactly yield the results I'm looking for, although similar.

avatar image Seth-Bergman · Jul 19, 2012 at 06:34 AM 0
Share

if you know how far though, you could set the increment exactly, by setting speed to the number of degrees, no?

i.e.

RotateAround(targetPosition,Vector3.up,angleInDegrees);

call once, and it would snap to the new position, I believe..

Anyway, sorry if I'm no 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

6 People are following this question.

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

Related Questions

How do I combine Orbiting with mouse drag and with a button click? 0 Answers

Rotate camera to object on sphere 1 Answer

Touch mouseorbit 5 Answers

Mouse Orbit snapping issues 0 Answers

Help understanding transform 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