-
Notifications
You must be signed in to change notification settings - Fork 22
/
DistanceEvents.py
47 lines (33 loc) · 1.64 KB
/
DistanceEvents.py
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
import avango
import avango.script
from avango.script import field_has_changed
import math
class DistanceEvents(avango.script.Script):
DistanceToGround = avango.SFFloat()
def __init__(self):
self.super(DistanceEvents).__init__()
self._character_control = None
self._smaller_than = []
self._bigger_than = []
def my_constructor(self, character_control):
self._character_control = character_control
def smaller_than(self, distance_to_ground, current_animation_name,
next_animation_config, blending_duration=0.5):
self._smaller_than.append((distance_to_ground, current_animation_name,
next_animation_config, blending_duration))
def bigger_than(self, distance_to_ground, current_animation_name,
next_animation_config, blending_duration=0.5):
self._bigger_than.append((distance_to_ground, current_animation_name,
next_animation_config, blending_duration))
@field_has_changed(DistanceToGround)
def distance_check(self):
cur_anim = self._character_control.get_current_animation()
if cur_anim is not None:
for st in self._smaller_than:
if(math.fabs(self.DistanceToGround.value) < st[0] and
cur_anim.name == st[1]):
self._character_control.blend_animation(st[2], st[3])
for bt in self._bigger_than:
if(math.fabs(self.DistanceToGround.value) > bt[0] and
cur_anim.name == bt[1]):
self._character_control.blend_animation(bt[2], bt[3])