Commit 08f94e67 authored by Rugeon's avatar Rugeon

Added fourth 'unpredictable' behaviour that remains stationary until provoked

parent 36df2da9
......@@ -16,16 +16,14 @@ namespace Complete
switch (m_Behaviour) {
case 1:
return SpinBehaviour(-0.05f, 1f);
case 2:
return TrackBehaviour();
case 3:
case 0:
return FunBehaviour();
case 4:
case 1:
return DeadlyBehaviour();
case 5:
case 2:
return SpookedBehaviour();
case 3:
return HatterBehaviour();
default:
return new Root(new Action(() => Turn(0.1f)));
......@@ -64,41 +62,7 @@ namespace Complete
}
//
/* Example behaviour trees */
// Constantly spin and fire on the spot
private Root SpinBehaviour(float turn, float shoot) {
return new Root(new Sequence(
new Action(() => Turn(turn)),
new Action(() => Fire(shoot))
));
}
// Turn to face your opponent and fire
private Root TrackBehaviour() {
return new Root(
new Service(0.2f, UpdatePerception,
new Selector(
new BlackboardCondition("targetOffCentre",
Operator.IS_SMALLER_OR_EQUAL, 0.1f,
Stops.IMMEDIATE_RESTART,
// Stop turning and fire
new Sequence(StopTurning(),
new Wait(2f),
RandomFire())),
new BlackboardCondition("targetOnRight",
Operator.IS_EQUAL, true,
Stops.IMMEDIATE_RESTART,
// Turn right toward target
new Action(() => Turn(0.2f))),
// Turn left toward target
new Action(() => Turn(-0.2f))
)
)
);
}
private Root FunBehaviour()
{
......@@ -254,7 +218,8 @@ namespace Complete
);
}
private Root SpookedBehaviour()
private Root SpookedBehaviour()//Flees and makes no attempts to defend itself
{
return new Root(
new Service(0.2f, UpdatePerception,
......@@ -265,8 +230,7 @@ namespace Complete
Operator.IS_SMALLER_OR_EQUAL, 0.1f,
Stops.IMMEDIATE_RESTART,
// Stop turning if target is not off center
new Sequence(
StopTurning())),
StopTurning()),
new BlackboardCondition("targetOnRight",
......@@ -276,7 +240,7 @@ namespace Complete
new Action(() => Turn(1.0f))),
// Turn left toward target
new Action(() => Turn(-1.0f))
),
),
new Selector(//Go forwards or backwards at the same time as other actions
......@@ -292,16 +256,78 @@ namespace Complete
new Sequence(
new Wait(0.1f),
new Action(() => Move(-0.8f))
)
)
)
)
)
);
}
private Root HatterBehaviour()//Acts Questionably, has some intentionally wonky values
//Starts by not moving until the player gets close and then
//Starts moving and attacks
{
return new Root(
new Service(0.2f, UpdatePerception,
new Sequence(
new Selector(
new BlackboardCondition("targetOffCentre",
Operator.IS_SMALLER_OR_EQUAL, 0.4f,
Stops.IMMEDIATE_RESTART,
// Stop turning
new Sequence(
StopTurning(),
new Wait(0.1f)
)),
new BlackboardCondition("targetOnRight",
Operator.IS_EQUAL, true,
Stops.IMMEDIATE_RESTART,
// Turn right toward target
new Action(() => Turn(0.6f))),
// Turn left toward target
new Action(() => Turn(-0.7f)
)
),
new Selector(new BlackboardCondition("targetDistance",
Operator.IS_GREATER_OR_EQUAL, 25.0f,
Stops.IMMEDIATE_RESTART,
// Doesn't move until within a certain distance of the other tank
StopMoving()
),
new Selector(//Go forwards or backwards at the same time as other actions
new BlackboardCondition("targetInFront",
Operator.IS_EQUAL, true,
Stops.IMMEDIATE_RESTART,
// Go forwards if the target is in front
new Sequence(
new Wait(0.1f),
new Action(() => Move(0.8f)))
),
// Go backwards if the target is behind
new Sequence(
new Wait(0.1f),
new Action(() => Move(-0.8f))
)
)
),
new BlackboardCondition("targetDistance",
Operator.IS_SMALLER_OR_EQUAL, 25.0f,
Stops.IMMEDIATE_RESTART,
//Start shooting when within range,
ShortFire())
)
)
);
}
private void UpdatePerception() {
Vector3 targetPos = TargetTransform().position;
Vector3 localPos = this.transform.InverseTransformPoint(targetPos);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment