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:
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.
Try hero:freeze()
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.