Doodad Hitboxes and Solidity #6

Closed
opened 2019-05-07 20:45:54 +00:00 by kirsle · 0 comments

Add the ability for Doodads to define their own solid hitboxes in JavaScript code and ability to push back other actors who collide with it. This way, locked doors can act like solid walls until opened and trapdoors can prohibit movement from the wrong direction but open and allow movement when hit from their entrance side.

Implementation notes:

  • JavaScript API for Doodad script:
    • Add Self.SetHitbox(X, Y, W, H) for a doodad to register the shape of its hitbox, relative to its canvas box. (X=0 Y=0 being the top-left corner of the doodad's canvas).
      • The hitbox is primarily informative-only for the game engine to handle bouncing actors back if the doodad decides it doesn't like the collision and wants to act solid.
    • In the OnCollide handler, the engine will pass a boolean InHitbox if the actor colliding is already inside the doodad's hitbox. This way the OnCollide function can decide easily if it should return false to act solid and reject the collision.
  • Engine code (in Canvas.Loop()):
    • In the loop where we move all mobile actors and check collision with level geometry, also store each actor's Original Position and their New Position (as permitted by the level geometry collision checks)
    • In the following loop where we check if any actors' boxes are colliding, further check their Hitboxes and see if those collide (this provides the InHitbox boolean value)
    • The actors' OnCollide handlers are always called if the two actors' canvas boxes overlap.
    • If the OnCollide returns false, the Engine should move the other actor back (using the actor's Original and New Positions) until the actor's Hitbox is not overlapping the doodad's Hitbox.
Add the ability for Doodads to define their own solid hitboxes in JavaScript code and ability to push back other actors who collide with it. This way, locked doors can act like solid walls until opened and trapdoors can prohibit movement from the wrong direction but open and allow movement when hit from their entrance side. Implementation notes: * JavaScript API for Doodad script: * Add `Self.SetHitbox(X, Y, W, H)` for a doodad to register the shape of its hitbox, relative to its canvas box. (X=0 Y=0 being the top-left corner of the doodad's canvas). * The hitbox is primarily **informative-only** for the game engine to handle bouncing actors back if the doodad decides it doesn't like the collision and wants to act solid. * In the `OnCollide` handler, the engine will pass a boolean `InHitbox` if the actor colliding is already inside the doodad's hitbox. This way the OnCollide function can decide easily if it should `return false` to act solid and reject the collision. * Engine code (in `Canvas.Loop()`): * In the loop where we move all mobile actors and check collision with level geometry, also store each actor's Original Position and their New Position (as permitted by the level geometry collision checks) * In the following loop where we check if any actors' boxes are colliding, further check their Hitboxes and see if those collide (this provides the `InHitbox` boolean value) * The actors' OnCollide handlers are _always_ called if the two actors' canvas boxes overlap. * If the OnCollide returns false, the Engine should move the other actor back (using the actor's Original and New Positions) until the actor's Hitbox is not overlapping the doodad's Hitbox.
kirsle added this to the First Beta Release MVP milestone 2019-05-07 20:45:54 +00:00
Sign in to join this conversation.
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: SketchyMaze/doodle#6
There is no content yet.