Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Elliott Gossett
behavior-trees2
Commits
08f94e67
Commit
08f94e67
authored
Oct 26, 2017
by
Rugeon
Browse files
Added fourth 'unpredictable' behaviour that remains stationary until provoked
parent
36df2da9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Assets/Complete/Scripts/Tank/Behaviours.cs
View file @
08f94e67
...
...
@@ -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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment