FootSteps.as 1.0 KB

12345678910111213141516171819202122232425
  1. class FootSteps : ScriptObject
  2. {
  3. void Start()
  4. {
  5. // Subscribe to animation triggers, which are sent by the AnimatedModel's node (same as our node)
  6. SubscribeToEvent(node, "AnimationTrigger", "HandleAnimationTrigger");
  7. }
  8. void HandleAnimationTrigger(StringHash eventType, VariantMap& eventData)
  9. {
  10. AnimatedModel@ model = node.GetComponent("AnimatedModel");
  11. AnimationState@ state = model.animationStates[eventData["Name"].GetString()];
  12. if (state is null)
  13. return;
  14. // If the animation is blended with sufficient weight, instantiate a local particle effect for the footstep.
  15. // The trigger data (string) tells the bone scenenode to use. Note: called on both client and server
  16. if (state.weight > 0.5f)
  17. {
  18. Node@ bone = node.GetChild(eventData["Data"].GetString(), true);
  19. if (bone !is null)
  20. SpawnParticleEffect(bone.worldPosition, "Particle/SnowExplosionFade.xml", 1, LOCAL);
  21. }
  22. }
  23. }