So what I'm working on (loosely) at the moment is basically a detect-spawn-and-attack method a la left 4 dead or else call of duty. So basically an avie walks close to a spawning point, the spawning region detects the avie's presence, spawns a bot, sets the bot to follow the avie and sets the bots belligerence level to "hostile".
Then the bot will follow the avie till it gets close enough and then it will attack which means run the appropriate attack anim and then call the code to do damage to the avie.
Rather than do all of this code myself I can piggyback on the existing follow code and at the same time change the belligerence state to hostile. Then I can mod the code that stops the avie from walking when it's close enough (in the follow code) to instead check to see the attack state and take appropriate action instead.
So here's the follow code in rexbot.cs with the appropriate places to mod commented:
//this is the follow code
CurrentFollowTimeBeforeUpdate++;
if (CurrentFollowTimeBeforeUpdate == FollowTimeBeforeUpdate)
{
Vector3 diffAbsPos = FollowSP.AbsolutePosition - m_scenePresence.AbsolutePosition;
if (Math.Abs (diffAbsPos.X) > m_closeToPoint || Math.Abs (diffAbsPos.Y) > m_closeToPoint)
{
NavMesh mesh = new NavMesh ();
bool fly = FollowSP.PhysicsActor == null ? ShouldFly : FollowSP.PhysicsActor.Flying;
mesh.AddEdge (0, 1, fly ? TravelMode.Fly : TravelMode.Walk);
mesh.AddNode (m_scenePresence.AbsolutePosition); //Give it the current pos so that it will know where to start
mesh.AddEdge (1, 2, fly ? TravelMode.Fly : TravelMode.Walk);
mesh.AddNode (FollowSP.AbsolutePosition); //Give it the new point so that it will head toward it
SetPath (mesh, 0, false, 10000, false); //Set and go
}
else //distance is less than the follow range.
//in here (the else block) we need to check if we are to attack
//(if the bot is hostile we attack
//otherwise we just stop the bot
{
//if the bot is hostile we attack
//attack code goes here
//else
//Stop the bot then
State = RexBotState.Idle;
m_walkTime.Stop ();
m_startTime.Stop ();
}
//Reset the time
CurrentFollowTimeBeforeUpdate = -1;
}
No comments:
Post a Comment