Game Development Reference
In-Depth Information
Vector3 playerFacing3D = Vector3( playerFa-
cing2D . x ,
playerFacing2D . y , 0)
// Use cross product to determine which way
to rotate
Vector3 crossResult = CrossProduct( playerFa-
cing3D ,
Vect-
or2 (0,1,0))
// Clockwise is -z, and it means the angle
needs to be negative.
if crossResult . z < 0
angle *= -1
end
// Determine which enemies are in range
foreach Enemy e in gameWorld
// Convert Enemy's position to 2D coordin-
ate
Vector2 enemyPos2D = Vector2 ( e . position . x ,
e . position . z )
// Construct vector from player to enemy
Vector2 playerToEnemy = enemyPos2D - play-
erPos2D
// Check the length, and see if it's with-
in range
if playerToEnemy .Length() <= range
// Rotate playerToEnemy so it's orien-
ted relative to
// the player's facing (using a 2D ro-
tation matrix).
playerToEnemy = Rotate2D( angle )
// Make a radar blip for this Enemy
RadarBlip blip
// Take the playerToEnemy vector and
convert it to
// offset from the center of the on-
screen radar.
Search WWH ::




Custom Search