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 me1501 · Mar 22, 2013 at 02:01 AM · rotationorbitcirclemove object

How do you orbit an object over a point on the map in a circle, with the object facing in the correct direction?

I have created a helicopter over terrain (say at y=50). I have a terrain that is 500x 500. I would like the helicopter to orbit with a radius of 50 (available for change above the point in a variable). I would like to have a speed variable that I can set set based on how it looks.

I need it to orbit at the same altitude in a circle in the center of the map (250,0,250), with the helicopter rotating to always face forward on the flight path.

I have some orbiting code here that makes the helicopter go in a circle, but I do not know how to face the helicopter forward along the flight path. I am not fully happy with the code, as when I tweak settings it also seems to make the circle elongate and have strange behaviour based on various combinations of speed, angle rotation, and radius. Additionally, this code does not orbit around the point but in a circle to the north of it (along the z axis forward). Please recommend some easier code or tweaks!!!! Thank you!!

 #pragma strict
 var speed = .5; // speed .5 seems to work, with radius 20, and change angle 10, but it seems eliptical
 
 var radius = 20.0;
 
 var angle = 0.0;
 
 var changeAngle=10; // change the Angle around the cirlce
 
 var StartX = 250; // origin points for circle
 
 var StartY =250;
 
 var x=0.0;
 
 var y=0.0;
 
 function Update () {
 
 // this is the code to move it in a circle
 
     x = (radius * Mathf.Cos(angle));
 
     y= -(radius * Mathf.Sin(angle));
 
 //Latest
 
     transform.Translate(x*speed*Time.deltaTime,y*speed*Time.deltaTime,0); // this seems to work moving in circle of right radius
 
 
     angle = angle + changeAngle* Mathf.Deg2Rad * speed*Time.deltaTime;
 
 //Need some lookat code here
 
 }
Comment
Add comment · Show 1
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 Benproductions1 · Mar 22, 2013 at 02:08 AM 0
Share

FOR$$anonymous$$AT YOUR CODE!!

1 Reply

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

Answer by robertbu · Mar 22, 2013 at 05:53 PM

In Unity there are a number of simpler ways to accomplish the same task. Attach the following script to your helicopter. Set the pivot to the position in the air around which you want your helicopter to rotate. Place your helicopter at one position on the circle out from the pivot.

 var speed : float = 30.0;
 private var pivot : Vector3 = new Vector3(0,50,0);
 
 function Update () {
     transform.RotateAround(pivot, Vector3.up, speed * Time.deltaTime);
 }

 
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 me1501 · Mar 23, 2013 at 01:23 PM 0
Share

robertu:

This is exactly right! Thank you for the help!

avatar image robertbu · Mar 23, 2013 at 03:59 PM 0
Share

If you are satisfied, click the checkmark next to the answer to mark it as having been answered.

avatar image Erisat · May 22, 2014 at 10:48 PM 0
Share

Thanks robertbu, I also found this helpful. I was overcomplicating it in my thoughts, as I was unaware of RotateAround function

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

11 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

Related Questions

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

Move object from A to B around Zero 1 Answer

Rotate camera to object on sphere 1 Answer

Touch mouseorbit 5 Answers

Mouse Orbit snapping issues 0 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