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 discoelf · Oct 11, 2011 at 07:31 AM · vector3rotateorbit

How do I make an object orbit another object

Someone on here said use the transform.RotateAround() but that's all the hints they gave to another user. Since I am new to scripting entirely I'm finding it difficult to put the pieces together on my own. When I think I'm starting to grasp it, I try it out and it pops up a ton of red errors.

like the example script in Unity's reference. transform.RotateAround (Vector3.zero, Vector3.up, 20 * Time.deltaTime); that works well to rotate the object around the whole world, but I want it to orbit an object, so I tried adding the orbiting object as a child of the object I wanted it to orbit and then gave the child object the follow script to follow the main object but it just sat there, and didn't move at all.

also I didn't understand the script supplied in reference because

transform.RotateAround is the function right? and then the options are (Vector3.zero, Vector.up, 20 * Time.deltaTime);

so I thought, the three things are the vector3? (x,y,z) and so setting it to (2,5,20); would tell it to rotate around in a chaotic orbit, but instead it just yelled at me and said it didn't understand what I was trying to tell it.

Comment
Add comment · Show 2
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 CHPedersen · Oct 11, 2011 at 07:41 AM 0
Share

Code doesn't yell. ;) Edit your question to supply the code you've written so far (the relevant parts of it, that is), then we can help you correct it.

avatar image discoelf · Oct 11, 2011 at 08:40 AM 0
Share

I have no official code. just a large sphere and a small sphere that I want to orbit the large sphere. Any code I try, I get rid of when it doesn't work :) like I just tried this

function Update () {

GameObject.Find ("Planet2").transform.RotateAround;

}

and it said "Expression in statements must only be executed for their side-effects."

I figured this would tell it "find Planet2, then rotate around it" that's how I'd read it if I was a computer.

when I tried this one, both spheres vanished from the screen ...

function Update () {

GameObject.Find ("Planet1").transform.RotateAround (Vector3.zero, Vector3.up, 20 * Time.deltaTime);

}

(i changed the item to planet 1 because i had that backwards) but then I made them both separate objects so that one isn't the child and that makes planet 1 fly around in huge circles it seems but not around my planet close enough.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Lantral · Oct 11, 2011 at 09:28 AM

Looks like you need a kind of point gravitation, which can be better done with forces like this (my noob-version could for sure done more elegant):

 var GravIntensity : float = 1;
 function OnTriggerStay (other : Collider) {
        if (other.attachedRigidbody) {
           var dist = Vector3.Distance(gameObject.transform.position , other.transform.position);
           other.attachedRigidbody.AddForce( (gameObject.transform.position - other.transform.position)/dist/dist*GravIntensity);
        }
     }                              
                       

Put the script to the attracting objects and give them a trigger-sphere. Then all objects within the "GravitationSphere"(for reducing the calculation needed) with a physical body (ridgetbody) will be attraced. Hope it helps.

Comment
Add comment · Show 1 · 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 Lantral · Oct 11, 2011 at 09:48 AM 0
Share

Ah - and I almost forgot to mention: And after that you give the moving object a soft forward push on awake. Then (if the gravitation and the movmentspeed is correct it will get on a circle - or more possibly - a elyptic path around the attractor).

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

RotateAround and Character Controller 1 Answer

Rotating a character's velocity? 3 Answers

unknown axis of rotation 1 Answer

Rotate vector around vector? 2 Answers

Having trouble making my camera orbit an object 2 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