|
The first 4 parameters are pretty easy to understand. We pass our player character and the 3 components of the surface normal to the function. The final 2 components are a bit trickier. The first of the two represents the axis we want to align along. For our implementation we want to pass a 2 for the Y-axis.
This means we want to align the character to this vector along his local up-down axis. The final parameter should be a floating-point number between 0 and 1, which represents the speed at which the character will snap to the vector.
In this case a 1 has been passed to make the alignment immediate. Smaller values will allow for interpolation between the previous alignment and the new alignment.
Next, we check to see if we are colliding with the planetoid or if we are above it because we jumped or are in orbit.
The EntityCollided() call requires two parameters which are the player character entity and the collision type mask we want to search for.
At the top of the program we created two types of collision masks. The first was a DYNAMIC type and the second was a STATIC type.
Obviously, the player character is dynamic and the planetoids are static because they don't move. So this call tells us if the player character of collision type DYNAMIC has collided with some other object (any other object) of type STATIC.
If we are colliding then we set our jumpTimer to the current time and we zero out our velocity. In the updateControl() code we allow the character 250 milliseconds of boost along the surface normal for jumping.
Once those 250 milliseconds are exceeded (or the player lets go of the jump button) the jump force will no longer be applied and the character must touch base to jump again. Finally back in the updatePhysics() call if we aren't colliding then we subtract the current surface normal from our velocity and translate our character back toward the planetoid.
The final component of the updatePhysics() function checks the planetoidClass list to see if we're actually closer to some other planetoid. If we are then we switch planetoids so the next time updatePhysics() is called we'll check with this new planetoid to calculate gravity.
Conclusion
In closing, it's obvious that there is much more to Super Mario Galaxy than the cool gravity mechanic the developers employed. Although the included source code covers things like camera tethering and control, it only scratches the surface of what went into making Super Mario Galaxy a polished gem and an achievement in gameplay.
Of course, the one feature that wasn't included in other Mario games was the gravity effect and that's what distinguished Galaxy from the rest of the series and indeed the rest of the industry this past holiday season.
Hopefully, this segment of Games Demystified offered a useful peek inside the underpinnings of game development. Until next time... Waahoo!
|
PS Next time, set your example NOT at 640x480 fullscreen, or it will crash for users without a prehistoric monitor supporting that low resolution, I had to download the source and recompile it running on a window to see your stuff!
If it can work in Shockwave3D, it can work anywhere! ;-)
Now check out Serious Sam's gravity handling. They did it using zones (defined in the level editor) and it works very well. It is also easier to implement well since you don't need to worry about any smoothing. I suspect that SMG may well have used a hybrid of these two approaches.
This will help us to acquire some more basic knowledge about gravity and it's use on games, which are very demanding right now.
Keep up the good work, and I want to read the next ones.
The only problem I ran into using this method was that snapping an object instantly to a new surface normal sometimes caused its ray to hit the polygon that it was previously using to calculate its up vector (when moving slowly along a "downward" slope, that is). I ended up scrapping this method because of the jittery back and forth effect that it was causing, eventually spiraling the object out of control into oblivion... maybe if I had LERPed the rotation slowly as mentioned in this article, I wouldn't have had the problems that I did.
Oh well... live and learn. Good article! :)
I love mario brother, I used to play all day when i was a kid...missed them :)