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 timaouxQC · Apr 07, 2013 at 08:48 PM · planetasteroid

[Solved]How to make a planet gravity that affect asteroid ?

Hi, as you can read in the title i want to know how to make a planet gravity that affect the asteroids with rigidbody, and if it hit something big the asteroid will get out of the planete orbit.

that is what i did:

 var Forward_Speed : float = 0.2;
 var Direction : Transform;
 
 var Planet : Transform;
 var Speed : float = 0.8;
 
 function Start() {
     Gravity = 0.00;
 }
 function LateUpdate () 
 {    
     rigidbody.AddForce(Direction.TransformDirection(Vector3.forward * Forward_Speed * Time.deltaTime));
     
     transform.RotateAround(Planet.transform.position, Vector3.up,Speed * Time.deltaTime);
 }


Thank you in advance and sorry for my bad english :)

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 sdgd · Apr 08, 2013 at 03:30 PM 4
Share

if you have reedit your question to [SOLVED] why don't you accept the answer that was helpful to you?

if you do not know how watch this: Unity Answers Tutorial

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by lktfl · Apr 08, 2013 at 05:12 AM

Have you checked the planetary gravity script on UnityWiki? **Here**

It will give you a starting place for your gravity script.

I wouldn't do important physics stuff like gravity inside of LateUpdate(). You should do those kinds of calculations in Update() or FixedUpdate().

Also, if you want to have something like have a gravitational radius you just need to:

1) get the distance between attracting object and the attracted object. Do this by saying:

 var distance = Vector3.Distance(attractingObject.transform.position, attractedObject.transform.position);


or

 var distance = attractingObject.transform.position - attractedObject.transform.position;  


2) create an if statement to check if your attracted object is inside your attracting object's gravitational radius:

 var gravitationalRadius : int;
 
 function Update(){

    //Do stuff

    if ( distance <= gravitationalRadius){
 
       // Do gravitational physics stuff here
 
    }
 
 }


Comment
Add comment · 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
0

Answer by HunterKrech · Apr 08, 2013 at 12:37 AM

Did this Same thing for my game here .

 void OnTriggerStay(Collider Me)
 {
     GravDir = PlanetPos.transform.position - transform.position;
     if(Me.gameObject.tag == "GravityField")
     {
         rigidbody.useGravity = false; gravity, or whatever
         transform.position = GravDir;
     }    
         

 }
      void OnTriggerExit(Collider Me)
 {
     if(Me.gameObject.tag == "GravityField")
     {
         rigidbody.useGravity = true;// depending if you want to re-apply
         rigidbody.constantForce.force = Vector3.zero;
         addingForce = false;    
     }
 } 


Make sure that you attach a large sphere collider to the planet, that is triggered, and put this code on the ateroids.

Comment
Add comment · 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
0

Answer by arjunxxxl · Jun 21, 2018 at 04:07 AM

I have made video to simulate realistic asteroid gravity. Take a look here : Gravity Simulation

Comment
Add comment · 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

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

Question about distant objects 3 Answers

Planet Rotation 2 Answers

Planetary perlin noise? My oceans are too patchy. 2 Answers

Mapping Cube to Sphere - Using 64 planes as a cube "side" 1 Answer

Have rigid body enter a planets orbit but always be able to escape it 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