How to make a planet with gravity?
Like mario Galaxy
Answer by Jawchewa · Jun 08, 2017 at 07:54 PM
There are a couple ways to do this. They basic idea is generally that you are going to want to have a rigidbody, and always apply a force pushing it into whatever direction is currently "down," while also having some logic to set the correct rotation. I would probably recommend looking into some tutorials to give you a better explanation. They'll probably give much more detail than any answer here could give. Here's a few to help you get started:
https://www.youtube.com/watch?v=gHeQ8Hr92P4
https://mikeloscocco.wordpress.com/2015/10/13/mario-galaxy-physics-in-unity/
Answer by DirtyFred · Jun 08, 2017 at 07:56 PM
Hi there,
I was searching for this a while ago and found this tutorial. This can set you on the right track.
I hope it helped.
Answer by Erathor · Sep 01, 2017 at 09:19 AM
Hey man I made one actually and it is quite simple ... it adds force to every object with a Rigidbody based on the distance they are away from each other.... you can also do some nice orbital simulation with this... pretty awesome... so you would only have to put this script somewhere once....
This is the class:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class world_gravity : MonoBehaviour {
IEnumerator Routine()
{
while (true)
{
Rigidbody[] Rigidbodies = FindObjectsOfType(typeof(Rigidbody)) as Rigidbody[];
for(int x = 0; x < Rigidbodies.Length;x++)
{
yield return new WaitForSeconds (0);
for(int y = 0; y < Rigidbodies.Length;y++)
{
if (x != y)
{
Rigidbodies [x].AddForce ((Rigidbodies [y].gameObject.transform.position - Rigidbodies [x].transform.position) * (Rigidbodies [y].mass / Vector3.Distance (Rigidbodies [x].transform.position, Rigidbodies [y].transform.position)));
yield return new WaitForSeconds (0);
}
}
}
yield return new WaitForSeconds (0);
}
}
// Update is called once per frame
void Awake () {
StartCoroutine (Routine());
}
} hope you like it :D
Answer by arjunxxxl · Jun 21, 2018 at 04:08 AM
I have made video to simulate realistic asteroid gravity. Take a look here : Gravity Simulation