# Planetary Gravity physics Error

Discussion in 'Physics' started by yazsh_, Jan 16, 2015.

1. ### yazsh_

Joined:
Oct 3, 2014
Posts:
10
Summary:

I have a working planetary physics system. Unfortunately, my characters easily gain enough momentum to be shot out of orbit at high speeds fairly easily. I believe this is due to the fact that my character controller updates the character's rigidbody2D.velocity variable for horizontal movement.

I have follow followed the guide in the video below, but tried it in 2 dimensions.

Is there a way to solve build up of momentum, either by changing the way gravity works or taking a different tact for the character controller? The guide I used uses the movePosition function, but I wasn't able to get it to work properly in 2d (at least with . Thanks for the help!

Code Used:
Currently I handle horizontal movement with this code. I multiply it by this.transform.right so it always pushes clockwise. I also add it to the current velocity so changing velocity doesn't affect my jump movements.

if (Input.GetAxis ("Horizontal") !=0) {
float horizForce = Input.GetAxis("Horizontal") * 4f;
Vector2 po= (this.transform.right * horizForce);
po.y += this.rigidbody2D.velocity.y;
this.rigidbody2D.velocity = po;
}

I also use the below code to rotate my character so they always point towards the planet they are on. This differs slightly from what is in the guide. The "target" variable refers to the player and "this" refers to the planet they are currently on.

Quaternion rot = Quaternion.FromToRotation ( Vector3.up, (target.transform.position - this.transform.position) ) ;
target.transform.rotation = Quaternion.Lerp (target.transform.rotation, rot , .1f * Time.time);

2. ### andeeeee

Joined:
Jul 19, 2005
Posts:
8,768
Are the characters actually supposed to be orbiting the planet or are they just walking around on the surface but need to jump and be brought back down in the correct direction?