July 13, 2010

3D Planet Gravity

This morning, I woke up with an unexplained thought in my head.
I knew exactly how to implement 3D gravity such as that in Super Mario Galaxy.
I'm still not quite sure why I was thinking about that, or why I pushed all of my sheets onto the floor in my sleep, but I think I was right.

A basic concept of 2D rotational gravity is to send out 2 rays from the
bottom of the character, one closer to the front, and one closer to the back.
From this, you calculate the angle between them, and use it to properly
rotate your character, and set the gravity of the character.
Optionally, for a more complex, but smoother situation, you find
the potential collision point, and gradually move towards the spot right above it.

In order to do 3D gravity, it's a little different, but the concept should be the same.
Send out 3 rays in a triangular arrangement from the character, and calculate a triangle from the points.
Take the resulting triangle, and use it as a reference for gravity.

Easier said than done, but the idea is there.

No comments:

Post a Comment