Game Development Reference
In-Depth Information
{
transform.Translate(0,0,Time.deltaTime *
speed);
}
transform.position.y = target.position.y +
heightOffset;
}
}
else if(state == "idle")
{
this.animation.Play("idle");
event = "update";
if(event == "update")
{
...
}
}
}
function Update()
{
//draw the paths in the scene view of the editor
//while playing
graph.debugDraw();
if(CanShootTarget())
{
prevState = state;
state = "attack";
}
else if(CanSeeTarget())
{
prevState = state;
state = "pursue";
}
else
{
prevState = state;
state = "idle";
}
FSM();
}
Step 15. The preceding code now controls the shooting and pursuing
actions of the guard. Setting the state's event to enter has also been
replaced. If the NPC's previous state was different from the current state, it
runs the original event = “enter” code—the same as initializing a state.
The distance the NPC shoots and pursues is controlled by variables at the
Search Nedrilad ::




Custom Search