-
Notifications
You must be signed in to change notification settings - Fork 0
Component Hitbox
The hitbox component allows an entity to collide, touch and overlap with other entities. The two primary aspects of this functionality is to provide solid physical things to stand on and touch (like floors and walls), and to make entities do things to each other (like fireballs and coins).
addHitbox (name:String, group:String, priority:Int, x:Int, y:Int, w:Int, h:Int)
Two physical hitboxes cannot move into each other. This is the way we have walls, platforms and solid objects in the game.
Question: What of two hitboxes overlap during a micro-step?
Answer: Use their mass to determine which pushes which, and leave them touching but not overlapping.
Question: What if two hitboxes overlap because of teleportation?
Answer: Give the "crushed" event to both entities. Instantly push the two entities away from each other based on mass and position, and leave them touching but not overlapping.
Question: What if hitbox A pushes hitbox B, and hitbox B ends up overlapping with hitbox C?
Answer: Reverse the pushing back to how it started, and add C's mass to B, and redo the calculation.
Question: What if two hitboxes of infinite mass push against each other?
Answer: Reverse the push, leave them touching but not overlapping, stop all velocity.
Question: What if a hitbox finds itself pushed from both sides by hitboxes of infinite mass?
Answer: Give the "crushed" event to the hitbox, and treat the two infinite mass hitboxes as pushing each other.
Touching means physical hitboxes are right next to each other, so closely that if they were to move any closer to each other they would be overlapping. Touching is defined to happen in one of four directions: up, right, down, and left. Touching is identity-unspecific, meaning an entity does not know what it is touching, merely that it is is touching something physical. Furthermore, entities do not care if they are touching one or five things, being touched is a binary state.
Question: What happens when two hitboxes touch?
Answer: Each entity is given an event corresponding to the direction of the touch: "touchUp", "touchRight", "touchDown", and "touchLeft". However, this event is only sent if the entity previously saw that direction as untouched.
Question: What happens when two hitboxes stop touching?
Answer: Each entity is given an event corresponding to the direction of the touch: "lossUp", "lossRight", "lossDown", and "lossLeft". However, this is only true if there is nothing else still touching in that direction. For instance, if two players are standing on a platform, and one of them jumps, then the jumping player will see "lossDown" but the platform will not see "lossUp" since the other player is still standing on it.
A collision happens when two hitboxes are overlapping. By default it does nothing, but it allows us to put in behavior on entities for when they collide with other entities.
Question: What happens when two hitboxes collide?
Answer: Each entity is given a "collision" event every cycle where they keep overlapping.
Unlike collision, overlap only triggers the first cycle where two hitboxes are overlapping.
Question: What happens when two hitboxes overlap?
Answer: Each entity is given a "overlap" event.
Question: What happens when two hitboxes stop overlapping?
Answer: Each entity is given a "separate" event.