• 9
• 10
• 9
• 10
• 10

# How do I cause a character to jump away from point of origin (planet)?

This topic is 905 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am making a game for a class and part of the game is set up such that the player runs around a planet and the camera follows the player. In other words, if you zoom out and keep the camera stationary, you will see the player running around a planet with his feet always pointing toward the center of the planet.

I want to make the player jump away from the planet and have "gravity" pull him back.

Currently the game is set up such that when you press the space bar it gives the player a y velocity and gravity pulls him back. This works fine for a normal platformer game but if you have the player at an angle the x and y coordinates change depending upon the angle. I'm also not sure how to give the player an initial velocity because that would also depend on the angle.

It was suggested to someone else in this forum to create a gravitational force that affects the player and another force that opposes the player to keep him on the surface of the planet. I don't know how to do that either.

Thanks!

Zach

##### Share on other sites
character up direction = Normalize(character position - center of planet);
jump => character velocity += character up direction * jump speed;
gravity => character acceleration -= character up direction * gravitational force; // If you want to have a distance falloff like "real" gravity, use a standard gravitational equation here.

This is one general idea. You obviously will need to adapt this to factor in your timestep, etc. Edited by Nypyren

##### Share on other sites

Thank you very much for your help. I haven't been able to get it to work yet but I will keep trying.

Zach

##### Share on other sites
Nypyren has an excellent solution, I just wanted to add something.

When stating the problem you used the word angle. If you have a solution that involves using angles with trig functions (sin, cos, atan ect) then there is almost always a cleaner, faster, and more robust solution using vector algebra.

Instead of angles, think direction as defined by a unit vector. Instead of trying to calculate angle differences use dot product and cross product. Those are my two bits.