Gamasutra: The Art & Business of Making Gamesspacer
Games Demystified: Super Mario Galaxy
View All     RSS
August 17, 2018
arrowPress Releases
August 17, 2018
Games Press
View All     RSS
  • Editor-In-Chief:
    Kris Graft
  • Editor:
    Alex Wawro
  • Contributors:
    Chris Kerr
    Alissa McAloon
    Emma Kidwell
    Bryant Francis
    Katherine Cross
  • Advertising:
    Libby Kruse






If you enjoy reading this site, you might also want to check out these UBM Tech sites:


 

Games Demystified: Super Mario Galaxy


March 27, 2008 Article Start Previous Page 3 of 4 Next
 

The component we'll be focusing on is the updatePhysics() function - here's a code sample from that section:

;====== UPDATE PHYSICS =======================================

Function updatePhysics()

player.playerClass = Object.playerClass( localPlayer )

planetoid.planetoidClass = Object.planetoidClass( player\planetoid )

LinePick( EntityX( player\character ), EntityY( player\character ), EntityZ( player\character ), EntityX( planetoid\mesh ) - EntityX( player\character ), EntityY( planetoid\mesh ) - EntityY( player\character ), EntityZ( planetoid\mesh ) - EntityZ( player\character ) )

AlignToVector( player\character, PickedNX(), PickedNY(), PickedNZ(), 2, 1 )

player\nX# = PickedNX()

player\nY# = PickedNY()

player\nZ# = PickedNZ()

If (EntityCollided( player\character, STATIC ) )

player\jumpTimer = MilliSecs()

player\vX# = 0

player\vY# = 0

player\vZ# = 0

Else

player\vX# = player\vX# - PickedNX()

player\vY# = player\vY# - PickedNY()

player\vZ# = player\vZ# - PickedNZ()

TranslateEntity( player\character, player\vX#, player\vY#, player\vZ# )

EndIf

distance = EntityDistance( player\character, planetoid \mesh )

For planetoid.planetoidClass = Each planetoidClass

If ( EntityDistance( player\character, planetoid\mesh ) < distance ) Then player\planetoid = Handle( planetoid )

Next

End Function

;=============================================================

The first two lines in this function retrieve our player and the planetoid he inhabits. This sets us up to apply the calculations, which will allow gravity to occur between them. Next we cast a ray from our character's local center to the planetoids local center.

This call requires 6 parameters. The first 3 are the starting point of the ray and the last 3 are the distance along the (x, y, z) axes to cast our ray. We don't use the ray itself to calculate gravity. Instead we only use the ray to find a polygon between the player and the planetoid and extract its surface normal.



The first thing we do with the surface normal is character alignment. The call to AlignToVector() has 6 parameters; the object to be aligned, the vector to align to, the axis to align along, and the speed at which we interpolate or snap to this alignment.


Article Start Previous Page 3 of 4 Next

Related Jobs

Game Closure
Game Closure — Mountain View, California, United States
[08.16.18]

Senior Game Engineer (HTML5)
Boss Fight Entertainment
Boss Fight Entertainment — Allen, Texas, United States
[08.16.18]

Senior Server Engineer
Baidu USA
Baidu USA — Sunnyvale , California, United States
[08.16.18]

3D Tools Software Engineer
Defiant Studios
Defiant Studios — New York, New York, United States
[08.16.18]

Lead Engine Programmer





Loading Comments

loader image