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 CupOfMayo · Oct 26, 2013 at 11:07 PM · orbitdrawpredict

Predict orbit based on velocity and basic gravity script

So I have my basic planetary gravity script

 var other : GameObject;
 
 var gravity : float;
 
 var dist : float;
 
 var distSqr : float;
 
 var force : float;
 
 
 
 function FixedUpdate()
 {
     AddGravity();
 }
 
 function AddGravity()
 {    
     var dir = (other.rigidbody.position - rigidbody.position);
     dist = Vector3.Distance(other.transform.position, transform.position);
     distSqr = dist * dist;
     force = gravity / distSqr;
     rigidbody.AddForce(dir.normalized * force);    
 }

And it works perfectly fine, the thing is I want to draw the orbit before satellite finish one orbit. I was thinking about putting another object and getting velocity and other variables multiped(for example by 10) but that didn't work so well. Any help 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 fafase · Oct 27, 2013 at 12:02 AM

You can anticipate the path of an object simply getting its equation ahead of time.

Using wikipedia, for projecctile motion:

 x = initialVelocity * Mathf.Cos(angle) * time;
 y = initialVelocity * Mathf.Sin(angle) - 0.5f * gravity * time * time;

Where time is just how long the object has been flying. time is the value at the moment, time + 1 is the value ahead 1s and then you could plot a point there to show where the guy is going, same with +2 to have even further.

If your object is in ideal condition (no air resistance) then it is fairly simple, with air resistance, it gets trickier since it is based on geometry.

If you need 3D I think the z goes:

     z = initialVelocity * Mathf.Sin(angle) * time;

It would be nice if someone with a Phd in physics could confirm that.

Comment
Add comment · Show 4 · 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 CupOfMayo · Oct 27, 2013 at 12:29 PM 0
Share

Yes the object (satellite) don't have any drag, but can you tell me more about that and can i use it as Update? I mean like if i add force to a satellite it will draw on what orbit will it move (kinda like in ksp map view)?

avatar image fafase · Oct 27, 2013 at 03:45 PM 0
Share

It gets slightly more complex since for each point your gravity is now depending on the distance to the planet. You could use the inverse square law:

g = g$$anonymous$$ax / distance distance; g = (g < $$anonymous$$Value) ? 0 : g; // if g is too small, makes it 0 x = initialVelocity $$anonymous$$athf.Cos(angle) time; y = initialVelocity $$anonymous$$athf.Sin(angle) - 0.5f gravity time * time;

You would maybe only consider the closest planet or you will end up with astronomical calculation.

avatar image CupOfMayo · Oct 27, 2013 at 05:09 PM 0
Share

Okay I see, but unfortunately I am horrible at understanding new things :S, I know this is not a place for "hey i dont know how to do that, can you write script for me", but I still need some more information about how I use it. I guess i should use it with line renderer? but then I am not sure what does (angle) mean :(.

avatar image fafase · Oct 27, 2013 at 05:47 PM 0
Share

Better off reading this http://babek.info/libertybasicfiles/lbnews/nl130/proj3d.htm

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

15 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

Related Questions

Draw an orbital trajectory of a ship 1 Answer

draw planet orbit on solar system 0 Answers

Spawn in specific location random prefab 1 Answer

How to draw a Sprite on OnDrawGizmos() 0 Answers

How to do make up using brush to draw sprite and remove using shower? 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