Skip to content

Instantly share code, notes, and snippets.

@kergalym
Last active September 5, 2022 20:04
Show Gist options
  • Save kergalym/7a34d40250c90d9a03794442e1a0a2ed to your computer and use it in GitHub Desktop.
Save kergalym/7a34d40250c90d9a03794442e1a0a2ed to your computer and use it in GitHub Desktop.
[Panda3D] Horse Mounting State
self.mount_sequence = {npc_name: Sequence()}
def enterHorseMount(self, actor, child, parent):
if actor and parent and child:
actor_name = actor.get_name()
if not self.mount_sequence[actor_name].is_playing():
# Our horse (un)mounting animations have been made with imperfect positions,
# so, I had to change child positions to get more satisfactory result
# with these animations in my game.
mounting_pos = Vec3(0.5, -0.15, -0.45)
saddle_pos = Vec3(0, -0.32, 0.16)
mount_action_seq = actor.actor_interval(anim_names.a_anim_horse_mounting,
playRate=self.base.actor_play_rate)
horse_riding_action_seq = actor.actor_interval(anim_names.a_anim_horse_rider_idle,
playRate=self.base.actor_play_rate)
actor.set_python_tag("mounted_horse", parent)
mount_task_name = "{0}_npc_mount_helper_task".format(actor_name.lower())
taskMgr.add(self.npc_mount_helper_task,
mount_task_name,
extraArgs=[child, actor, mounting_pos, anim_names.a_anim_horse_mounting],
appendTask=True)
# Horse mounting consists of 13 intervals
a = Func(child.set_collide_mask, BitMask32.allOff())
b = Func(self.fsm_state_wrapper, actor, "generic_states", "is_using", True)
c = Parallel(mount_action_seq,
Func(child.reparent_to, parent),
Func(child.set_x, mounting_pos[0]),
Func(child.set_y, mounting_pos[1]),
Func(actor.set_z, mounting_pos[2]),
Func(child.set_h, 0),
)
d = Func(child.set_x, saddle_pos[0])
e = Func(child.set_y, saddle_pos[1])
# bullet shape has impact of gravity
# so make player geom stay higher instead
f = Func(actor.set_z, saddle_pos[2])
g = Func(child.set_collide_mask, BitMask32.bit(1))
h = Func(self.fsm_state_wrapper, actor, "generic_states", "is_using", False)
j = Func(self.fsm_state_wrapper, actor, "human_states", "horse_riding", True)
k = Func(self.fsm_state_wrapper, actor, "human_states", "is_on_horse", True)
l = Func(parent.set_python_tag, "is_mounted", True)
m = Func(taskMgr.remove, mount_task_name)
n = horse_riding_action_seq
self.mount_sequence[actor_name].append(a)
self.mount_sequence[actor_name].append(b)
self.mount_sequence[actor_name].append(c)
self.mount_sequence[actor_name].append(d)
self.mount_sequence[actor_name].append(e)
self.mount_sequence[actor_name].append(f)
self.mount_sequence[actor_name].append(g)
self.mount_sequence[actor_name].append(h)
self.mount_sequence[actor_name].append(j)
self.mount_sequence[actor_name].append(k)
self.mount_sequence[actor_name].append(l)
self.mount_sequence[actor_name].append(m)
self.mount_sequence[actor_name].append(n)
self.mount_sequence[actor_name].start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment