Author Topic: Stop hero animation outside collision  (Read 1254 times)

Starlock

  • Full Member
  • ***
  • Posts: 105
    • View Profile
Stop hero animation outside collision
« on: October 08, 2016, 10:16:35 pm »
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)

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1176
    • View Profile
Re: Stop hero animation outside collision
« Reply #1 on: October 08, 2016, 11:11:57 pm »
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.

Starlock

  • Full Member
  • ***
  • Posts: 105
    • View Profile
Re: Stop hero animation outside collision
« Reply #2 on: October 09, 2016, 02:52:54 am »
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.

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1176
    • View Profile
Re: Stop hero animation outside collision
« Reply #3 on: October 09, 2016, 07:21:58 am »
Try hero:freeze()

Starlock

  • Full Member
  • ***
  • Posts: 105
    • View Profile
Re: Stop hero animation outside collision
« Reply #4 on: October 09, 2016, 05:37:26 pm »
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.