andrew-peng-144 / js-explore-game

0 stars 0 forks source link

collision querying #3

Open andrew-peng-144 opened 3 years ago

andrew-peng-144 commented 3 years ago

a way to query any area in the world. i.e. a hitbox that only lasts 1 frame. useful for combat

andrew-peng-144 commented 3 years ago

Question: should this work with the handlerdef, or should it be entirely local within the function that calls the query?

Answer: probably work with handlerdef... but that means either

andrew-peng-144 commented 3 years ago

tried 3rd method

andrew-peng-144 commented 3 years ago

Prob doing 2nd method lol. 3rd is weird because it just repeats much of the collision code, and still calls the handler for it, meaning the handling of queries is in same file as handling 2 hitboxes, unclean...

So for 2nd method, with "active" flag, have a way to make a hitbox only active for 1 frame. Timeline should be like:

  1. hitbox is inactive. Something happens such that sets hitbox to be active.
  2. hitbox is active, so the collision code should treat it as such and handle collision with handlerdef. After handing, set hitbox to be inactive

There will still be querying in the future but it will not use the handler. Instead it will just return all the physicscomponents touching the queried area. Then in the local code user can decide what do with the returned physicscomponents.

andrew-peng-144 commented 3 years ago

To do it for melee attacks: Have a initially inactive entity placed anywhere on the map. Then if melee happens, move the entity to next to the attacker, then set it active. Then set it inactive after some frames, usually 1.