Game Development Reference
In-Depth Information
case bossEvents.inactive:
// Not doing anything, so nothing to do.
break;
You may be asking yourself, as your eyeballs roll over the following case statement,
" Yo, mister writer! Why don't we just use one of the Rigidbody 2D things and let the physics
engine drop 'em? Eh? ". The question itself though is fabulous! And I have a fabulous
answer for you—physics have chaos.
So, you may think the boss is going to land in a specific position, but certain things
may cause it to not happen. Maybe another object collides with it and pushes it
off course. Maybe the physics causes it to not stop at the exact position you want.
Essentially, this is the safest method—use movement functions to put the boss where
you want it to be. If you were working on a big action-oriented game and wanted an
enemy to jump a long distance—such as the Handymen in BioShock Infinite—chances
are you would shut off the physics for the enemy, move it along an arc, and when it
landed, turn the physics back on. Doing all this means there will never be any misses,
which is exactly what the following code does:
case bossEvents.fallingToNode:
if(transform.position.y >
targetNode.transform.position.y)
{
// Movespeed here is negative,
//so the object moves downwards
transform.Translate(new Vector3(0f,
-moveSpeed * Time.deltaTime, 0f));
if(transform.position.y < targetNode.
transform.position.y)
{
Vector3 targetPos =
targetNode.transform.position;
transform.position = targetPos;
}
}
else
{
// Create the 'Hit Ground' smoke FX
createDropFX();
timeForNextEvent = 0.0f;
currentEvent = bossEvents.waitingToJump;
}
break;
case bossEvents.waitingToFall:
 
Search WWH ::




Custom Search