imagination XD

realizing dream

[Experiment] Planetary Gravity with Vector3.normalized

1 Comment

I’ve been learn on my physx lesson about normals. I know that normal lines is always pointing up (transform.up of an object faces). And then i’m trying to make Planetary Gravity with Vector3.normalized. It really works! However, it’s not working as perfect as i expect. When the object collides an atmosphere, the collided object will be pulled by the planet. Even you shoot the object from the south pole of the planet, this script will still pull the object to the ground. I will share this script to everyone (since it’s hard to find at google). Enjoy !

#pragma strict
var gravityPower = -500.0;
var planet : Transform;

function Start(){
    Physics.gravity = awakeGravity;
// use OnTriggerStay. If i use OnTriggerEnter, 
it will just pull the object once.
for the performance option, i don't know

 function OnTriggerStay(col : Collider){
  var direction = col.transform.position - transform.position;
  col.attachedRigidbody.AddForce(direction.normalized * gravityPower);
  col.transform.rotation = 
* Quaternion.Euler(;

Some ScreenShot



Started making games since 13 year old. 3D CGI Weeaboo | VFX Otaku | Anime Researcher | Indie Game Dev | VR Chuunibyou

One thought on “[Experiment] Planetary Gravity with Vector3.normalized

  1. I like the valuable information you provide for your articles.
    I will bookmark your blog and take a look at again here frequently.
    I am relatively certain I’ll be told lots of new stuff proper here! Best of luck for the following!


Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s