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 /
This question was closed Sep 23, 2013 at 09:35 AM by Fattie for the following reason:

Duplicate Question

avatar image
0
Question by criddle98 · Sep 23, 2013 at 02:31 AM · physicsprocedural-generation

Spherical Gravity

How would I go about adding gravity to a sphere(planet) I am also wanting to add terrain to the planet in the future so how would I go about doing this? I am fairly new to scripting in unity, so any help would be fantastic!

Comment
Add comment · Show 5
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 syclamoth · Sep 23, 2013 at 03:33 AM 2
Share

Word of warning- do not expect people to answer questions that consist of a very long title, no body, and virually useless tags. I've cleaned this one up for you, and clunk has very kindly chosen to answer you anyway, but in future please try to ask more clearly formatted questions.

avatar image clunk47 · Sep 23, 2013 at 03:34 AM 0
Share

@syclamoth +1 for the Edit ;)

avatar image Fattie · Sep 23, 2013 at 09:35 AM 1
Share

There are WAY TOO $$anonymous$$ANY IDENTICAL QUESTIONS on this. $$anonymous$$oderators, you are allowed to use the "close" button.

avatar image clunk47 · Sep 23, 2013 at 04:55 PM 0
Share

Sry @Fattie, fell asleep XD

avatar image Sawney · Mar 24, 2019 at 12:44 PM 0
Share

Video tutorial for spherical gravity: https://www.youtube.com/watch?v=UeqfHkfPNh4

1 Reply

  • Sort: 
avatar image
2
Best Answer

Answer by clunk47 · Sep 23, 2013 at 03:29 AM

Well, you need to ask one question at a time here. You also need to be a bit more specific on your needs. I'm not sure what you're asking as far as adding gravity to a sphere. If you're talking about adding a gravitational "pull" to a sphere, like a "planet", you could try something as simple as placing all the rigidbodies out in "space" into an array or list. Then in a for statement, get the distance between your planet and each body out in space. Make a range, in this example is 100, and have the planet pull those physical bodies toward it if they are close enough. I won't get into anything to detailed, or smooth functioning, because you weren't in any way specific. Try this out, break down the code, and look up each piece of it in the Unity Script Reference if you are not sure what it means. As for your terrain question, ask it as a separate question after you work this one out.

 //Example.cs
 
 using UnityEngine;
 using System.Collections;
 
 public class Example : MonoBehaviour
 {
     Object[] RBs;
     float range = 100.0f;
     float stopDistance = 10.0f;
     
     void Awake()
     {
         RBs = GameObject.FindObjectsOfType (typeof(Rigidbody));    
     }
     
     void Update()
     {
         foreach(Rigidbody RB in RBs)
         {
             float dist = Vector3.Distance(RB.transform.position, transform.position);
             if(dist < range && dist > stopDistance)
             {
                 RB.position = Vector3.MoveTowards(RB.position, transform.position, Vector3.Distance(RB.transform.position, transform.position) * Time.deltaTime);
             }
         }
     }
 }


Comment
Add comment · Show 6 · 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 syclamoth · Sep 23, 2013 at 03:44 AM 1
Share

Now try doing this for multiple planets all interacting with each other :P

avatar image clunk47 · Sep 23, 2013 at 03:49 AM 0
Share

Ahh, thanks for this reference, definitely something I will bookmark, because I'm still learning. :)

Didn't want to get too into detail in case this isn't what the PO is looking for, so made up a quick, clunky but functional example. +1 for the great wiki link, very useful information.

avatar image DaveA · Sep 23, 2013 at 03:50 AM 2
Share

If you want your feet on the ground, you will also need to worry about rotating your stuff, aligning their 'up' directions with 'out' from the center of the planet.

avatar image clunk47 · Sep 23, 2013 at 04:00 AM 0
Share

@criddle98 - Someone deleted your question originally, because it was vague, even with the title being too long, tags were not really a help either. But I undeleted it because I could see you really needed help. All the information provided should at least get you started, thanks to Syclamoth and DaveA, you have more to go off of than my simple answer alone. Definitely give up-votes to these guys for taking time to help resolve your issue.

avatar image syclamoth · Sep 23, 2013 at 04:14 AM 1
Share

I actually answered a similar question (pertaining to the 'feet-down' problem) earlier today- Rotate to Orient to Sphere Surface

Show more comments

Follow this Question

Answers Answers and Comments

21 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Bake mesh collider on separate thread? 0 Answers

2D 360 degress platformer example needed 0 Answers

How to set up a No Mans Sky type of infinite flight ? 1 Answer

Rotating an object to match a rigidbody's direction of movement. 2 Answers

How to decrease inertia for a rolling ball 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