playMaker

Author Topic: Gravity in the center of planets  (Read 3772 times)

Rockr

  • Playmaker Newbie
  • *
  • Posts: 2
Gravity in the center of planets
« on: April 06, 2012, 03:44:15 AM »
Hello, I'm making small game prototype and face with issue  ??? how to make several objects with gravity in the center of them like in Mario Galaxy, where character can jump from one planet to another. How can I set center of a planet as a center of a gravity? Thank you.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: Gravity in the center of planets
« Reply #1 on: April 07, 2012, 06:39:34 PM »
You have to do this manually with Add Force and some Vector actions to get a vector towards the planet.

Get the world position of the player, and subtract the position of the planet. Normalize this vector then Multiply by some factor (you'll need to tweak this value). Then use Add Force to push the player towards the planet center.

You have to use a few actions... If I have a chance, I'll make a Get Vector Towards action which would combine a few of these steps...

You'll probably want to align the player's up vector with the gravity vector, or the normal of the surface the player is on. Try Vector3 Rotate Towards for this...

Rockr

  • Playmaker Newbie
  • *
  • Posts: 2
Re: Gravity in the center of planets
« Reply #2 on: April 08, 2012, 01:38:59 AM »
Thank you very much for your detailed answer, Alex! I really appreciate this. I will try this way and write how it works.

markinjapan

  • Full Member
  • ***
  • Posts: 103
Re: Gravity in the center of planets
« Reply #3 on: April 08, 2012, 09:23:45 AM »
Hi, I was playing around with doing this the other day, very easy to do.

You can also use a ray cast to get the normal vector (of the surface you are standing on) and then invert, normalise, multiply, addforce. This is useful for non round surfaces.

treborjones

  • Playmaker Newbie
  • *
  • Posts: 24
Re: Gravity in the center of planets
« Reply #4 on: August 16, 2014, 02:41:09 PM »
Howdy peeps,

I wondered if anyone could show me a screen shot /share an fsm setup of this. I'm trying to achieve a gravitational pull of planets on a player ship (rigid body and applying a force in the direction of the planet) but cant  get it working.

I'm keen to get the force fading with distance from the planet as well.

Cheers in advance for any help.