Stop hero animation outside collision

Started by Starlock, October 08, 2016, 10:16:35 PM

Previous topic - Next topic
I'm trying to make a collision test on a custom entity  that changes the hero animation while overlapping. Setting the animation works, but the animation persists outside of the entity until the hero stops moving. What do I do to fix this?

This is the chunk:

Code ( lua) Select
  entity:add_collision_test("overlapping", function()
    if entity:overlaps(hero) then
      hero:set_animation("spring")
    end
    return true
  end)

You start an animation but you never stops it. So it only stops when another one is set, here by the engine when the hero stops moving.

What you can do is use a repetitive timer to check regularly if the entity is still overlapping the hero, and if not, stop the animation.

It works now, but is there a way to prevent the hero from using items during the collision? If an item is used the hero just ends up freezing.


Won't that just make the hero unable to move? The hero should be able to move, the problem is that he stops moving when he attempts to use his sword. I'm thinking of using on_command_pressed but I'm not sure what to do to make the hero unable to do anything besides move.