How to make mario galaxy gravity like?

How to make mario galaxy gravity like?
My try:

  def update(self, task):
        self.pFrom = self.np2.getPos();
        self.pTo =;
        result =, self.pTo);
        normal = result.getHitNormal();
        self.np2.setHpr(self.np2, Vec3( 90, 0, 90 ) );;;

But model bounces from surface and twitches. I use bullet engine.

1 Like

I haven’t tried this myself, but what I’d suggest is that you not use Bullet’s “gravity” feature, but instead apply the relevant forces yourself. (Especially if you want to have this gravity affect multiple objects, as objects at different points on the surface of a sphere will be subject to gravity pointing in different directions.)

So, presuming that you have a spherical celestial body on which a character stands, the force of its gravity would point from the position of the character towards the centre of the body, and thus give a vector that looks something like this:
gravityVector = celestialBody.getPos() - character.getPos()

You could then, I think, apply this as a force via Bullet’s “applyCentralImpulse” method–taking into account the delta-time for the current frame. Something like this:

finalGravity = gravityVector * graviyStrength * globalClock.getDt()

(Where the “gravityStrength” variable allows you to tune the strength of gravity.)

Now, you mention the character bouncing–that suggests to me that the “restitution” value of the surface may be too high. You could try setting it to a lower value via the “setRestitution” method. (Although I’m not sure of whether this would call for setting the value on the character, the celestial body, or both, offhand.)

Note again that I haven’t tested this myself, and so there might be errors in the above.

This isn’t the only way to take the challenge, but Mario galaxy itself used gravity fields, as seen in this video.

The benefit of gravity fields is you can have a “maximum force” that gets split evenly between any overlapping gravity fields a character is currently in. Alternatively, you can simply have the most recent gravity field take priority. Another benefit of gravity fields is that you can use them outside of the physics system to “cheat” and have enemies or objects align and behave like gravity is effecting them without actually using any expensive physics. (I.E. a bullet bill can simply be rotated to align with it’s point in the gravity field before moving forward, so it looks like it’s orbiting a planet.)

I don’t have too much experience with the third party physics systems like bullet, so you can feel free to ignore the rest of my reply since it isn’t really relevant to bullet but rather panda3d’s built in physics. I don’t want to try and convince you to not use bullet, since I don’t know what your game requires and it isn’t unlikely that bullet might suit your needs better.

For instance, if you simply want to use the most recent gravity field (which you might, as it makes things much more predictable when designing levels) a sphere can be represented by a LinearSinkForce, and a inside-out sphere (I.E. some of mario galaxy’s bonus rooms) could be represented by a LinearSorceForce.
Furthermore, if a gravity field needs to rotate, you can simply rotate a forcenode.

1 Like