-
Notifications
You must be signed in to change notification settings - Fork 2
/
FOLLOW.SC
73 lines (61 loc) · 1.55 KB
/
FOLLOW.SC
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
(script# FOLLOW)
(class Follow kindof Motion
;;; This class moves its client in such a way as to try and stay within
;;; a certain distance to another object.
(properties
who 0 ;who to follow
distance 20 ;try to stay at least this close to 'who'
)
(method (init theObj whom dist)
(if (>= argc 1) (= client theObj)
(if (>= argc 2) (= who whom)
(if (>= argc 3) (= distance dist)
)
)
)
;If the client is too far from the object being followed, start
;moving toward it.
(if (> (client distanceTo: who) distance)
(super init: client (who x?) (who y?))
; (super doit:)
)
)
(method (onTarget)
(<= (client distanceTo: who) distance)
)
(method (setTarget)
(cond
(argc
(super setTarget: &rest)
)
((not (self onTarget:))
(super setTarget: (who x?) (who y?))
)
)
)
(method (doit &tmp angle)
(if (> (client distanceTo: who) distance)
;If too far from the object being followed, move toward it.
(super doit:)
(if (== b-moveCnt 0)
(super init: client (who x?) (who y?))
)
else
;The client is just standing around near its destination. Pick
;the loop which faces in the destination's direction.
(= xLast (client x))
(= yLast (client y))
(= angle (GetAngle xLast yLast (who x?) (who y?)))
(if (client looper?)
((client looper?) doit: client angle)
else
(DirLoop client angle)
)
)
)
(method (moveDone)
;;; When done with the current leg of wandering, re-init: the motion
;;; to continue wandering.
; (self init: client distance)
)
)