Gamasutra is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Gamasutra: The Art & Business of Making Gamesspacer
Games Demystified: Super Mario Galaxy
View All     RSS
January 22, 2020
arrowPress Releases
January 22, 2020
Games Press
View All     RSS







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

Disbelief
Disbelief — Cambridge, Massachusetts, United States
[01.21.20]

Programmer
Yacht Club Games
Yacht Club Games — Los Angeles, California, United States
[01.20.20]

Senior Tools & Engine Programmer
HERE
HERE — Carlsbad, California, United States
[01.20.20]

Sr Software Enginer- Unity 3D
Wargaming Mobile
Wargaming Mobile — Berlin, Germany
[01.20.20]

Lead Gameplay Developer





Loading Comments

loader image