Game Development Reference
In-Depth Information
[System.Serializable]
public class condition_fartherThanThresh
: npcCondition {
3. The eval() method will have the same signature and implementation as the
closer condition script explained previously, except that instead of checking if
the distance is less than the threshold, you will check if the distance is great-
er than the threshold:
bool rval = false;
Vector3 vDisp =
(this.baseObj.transform.position -
trackObj.transform.position);
float dist = vDisp.magnitude;
if ( dist > thresh)
rval = true;
return rval;
Congratulations! You have combined the complement-condition script with the
closer-than script. With both of these combined, we will be able to make the NPC
start and stop a behavior based on proximity.
We need one more script to make the NPC respond to these proximity changes.
Since the NPC knows how to behave in the patrol and turnToPlayer states, we
want to make the NPC change the internal state as a response.
Implementing the response_changeState script
Let's create a response script that will change the internal state on the associated
npcScript class to a specified value. This helper script will prove very useful as it
will allow our NPC to react to conditions in the world by changing the npcScript
state to response.
1. Create a new script in the editor, and name it response_changeState .
2. As with the previous two cases, modify the class signature to make it inherit
from npcResponse (not npcCondition ), and be sure to add the explicit
serialization tag as well:
Search WWH ::




Custom Search