forked from Calamari/BehaviorTree.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
76 lines (68 loc) · 1.45 KB
/
Copy pathexample.js
File metadata and controls
76 lines (68 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//Sequence is child of Node
//Selector is child of Node
//Task is child of Node
BehaviorTree.register('previouslyGeneratedTask', new BehaviorTree.Task({
// Things to do on starting this task
start: function() {
},
// Things to do after finishing task
end: function() {
},
// Things to do on each loop cycle
run: function() {
this.success();
}
}));
var tree = new BehaviorTree({
'tree': new BehaviorTree.Sequence({
title: 'growing',
nodes: [
new BehaviorTree.Task({
title: 'leafing',
run: function() {
this.fail();
}
}),
'previouslyGeneratedTask',
new BehaviorTree.Selector({
title: 'shrinking',
nodes: [
new BehaviorTree.Decorator({
task: 'loosingLeafes'
})
]
})
]
})
});
// Set object the behavior is meant to work on
tree.setObject({});
/*
In this Tree, we use registered Nodes for the Tasks
Sequences and Selectors can be generated on the fly, using the given nodes and title
Given nodes can also be decorators or filters
*/
var tree2 = new BehaviorTree({
tree: {
title: 'planner',
type: 'Sequence',
nodes: [
{
title: 'fight',
type: 'Selector',
nodes: [
'sword',
'bareHands'
]
},
{
title: 'idle',
type: 'Selector',
nodes: [
'walkAround',
'standStill'
]
}
]
}
});