2022-01-17 04:09:27 +00:00
|
|
|
// Trapdoors.
|
2019-07-05 22:02:22 +00:00
|
|
|
|
2022-01-17 04:09:27 +00:00
|
|
|
// What direction is the trapdoor facing?
|
|
|
|
const direction = Self.GetTag("direction");
|
2019-07-05 22:02:22 +00:00
|
|
|
|
2022-01-17 04:09:27 +00:00
|
|
|
function main() {
|
2019-07-05 22:02:22 +00:00
|
|
|
// Set our hitbox based on our orientation.
|
2022-01-17 04:09:27 +00:00
|
|
|
let thickness = 10;
|
|
|
|
let doodadSize = 86;
|
2019-07-05 22:02:22 +00:00
|
|
|
if (direction === "left") {
|
|
|
|
Self.SetHitbox(48, 0, doodadSize, doodadSize);
|
|
|
|
} else if (direction === "right") {
|
Improve Collision Detection: More Active w/ Actors
* Improve the collision detection algorithm so that Actor OnCollide
scripts get called more often WHILE an actor is moving, to prevent a
fast-moving actor from zipping right through the "solid" hitbox and
not giving the subject actor time to protest the movement.
* It's implemented by adding a `Settled` boolean to the OnCollide event
object. When the game is testing out movement, Settled=false to give
the actor a chance to say "I'm solid!" and have the moving party be
stopped early.
* After all this is done, for any pair of actors still with overlapping
hitboxes, OnCollide is called one last time with Settled=true. This is
when the actor should run its actions (like publishing messages to
other actors, changing state as in a trapdoor, etc.)
* The new collision detection algorithm works as follows:
* Stage 1 is the same as before, all mobile actors are moved and
tested against level geometry. They record their Original and New
position during this phase.
* Stage 2 is where we re-run that movement but ping actors being
intersected each step of the way. We trace the steps between
Original and New position, test OnCollide handler, and if it returns
false we move the mobile actor to the Last Good Position along the
trace.
* Stage 3 we run the final OnCollide(Settled=true) to let actors run
actions they wanted to for their collide handler, WITHOUT spamming
those actions during Stage 2.
* This should now allow for tweaking of gravity speed and player speed
without breaking all actor collision checking.
2019-07-17 04:07:38 +00:00
|
|
|
Self.SetHitbox(0, 0, thickness, doodadSize);
|
2019-07-05 22:02:22 +00:00
|
|
|
} else if (direction === "up") {
|
|
|
|
Self.SetHitbox(0, doodadSize - thickness, doodadSize, doodadSize);
|
|
|
|
} else { // Down, default.
|
Improve Collision Detection: More Active w/ Actors
* Improve the collision detection algorithm so that Actor OnCollide
scripts get called more often WHILE an actor is moving, to prevent a
fast-moving actor from zipping right through the "solid" hitbox and
not giving the subject actor time to protest the movement.
* It's implemented by adding a `Settled` boolean to the OnCollide event
object. When the game is testing out movement, Settled=false to give
the actor a chance to say "I'm solid!" and have the moving party be
stopped early.
* After all this is done, for any pair of actors still with overlapping
hitboxes, OnCollide is called one last time with Settled=true. This is
when the actor should run its actions (like publishing messages to
other actors, changing state as in a trapdoor, etc.)
* The new collision detection algorithm works as follows:
* Stage 1 is the same as before, all mobile actors are moved and
tested against level geometry. They record their Original and New
position during this phase.
* Stage 2 is where we re-run that movement but ping actors being
intersected each step of the way. We trace the steps between
Original and New position, test OnCollide handler, and if it returns
false we move the mobile actor to the Last Good Position along the
trace.
* Stage 3 we run the final OnCollide(Settled=true) to let actors run
actions they wanted to for their collide handler, WITHOUT spamming
those actions during Stage 2.
* This should now allow for tweaking of gravity speed and player speed
without breaking all actor collision checking.
2019-07-17 04:07:38 +00:00
|
|
|
Self.SetHitbox(0, 0, doodadSize, thickness);
|
2019-07-05 22:02:22 +00:00
|
|
|
}
|
|
|
|
|
2022-01-17 04:09:27 +00:00
|
|
|
let animationSpeed = 100;
|
|
|
|
let opened = false;
|
2019-07-05 22:02:22 +00:00
|
|
|
|
|
|
|
// Register our animations.
|
2022-01-17 04:09:27 +00:00
|
|
|
let frames = [];
|
|
|
|
for (let i = 1; i <= 4; i++) {
|
2019-07-05 22:02:22 +00:00
|
|
|
frames.push(direction + i);
|
|
|
|
}
|
|
|
|
|
|
|
|
Self.AddAnimation("open", animationSpeed, frames);
|
|
|
|
frames.reverse();
|
|
|
|
Self.AddAnimation("close", animationSpeed, frames);
|
|
|
|
|
2022-01-17 04:09:27 +00:00
|
|
|
Events.OnCollide((e) => {
|
2019-07-05 22:02:22 +00:00
|
|
|
if (opened) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Is the actor colliding our solid part?
|
|
|
|
if (e.InHitbox) {
|
|
|
|
// Are they touching our opening side?
|
Improve Collision Detection: More Active w/ Actors
* Improve the collision detection algorithm so that Actor OnCollide
scripts get called more often WHILE an actor is moving, to prevent a
fast-moving actor from zipping right through the "solid" hitbox and
not giving the subject actor time to protest the movement.
* It's implemented by adding a `Settled` boolean to the OnCollide event
object. When the game is testing out movement, Settled=false to give
the actor a chance to say "I'm solid!" and have the moving party be
stopped early.
* After all this is done, for any pair of actors still with overlapping
hitboxes, OnCollide is called one last time with Settled=true. This is
when the actor should run its actions (like publishing messages to
other actors, changing state as in a trapdoor, etc.)
* The new collision detection algorithm works as follows:
* Stage 1 is the same as before, all mobile actors are moved and
tested against level geometry. They record their Original and New
position during this phase.
* Stage 2 is where we re-run that movement but ping actors being
intersected each step of the way. We trace the steps between
Original and New position, test OnCollide handler, and if it returns
false we move the mobile actor to the Last Good Position along the
trace.
* Stage 3 we run the final OnCollide(Settled=true) to let actors run
actions they wanted to for their collide handler, WITHOUT spamming
those actions during Stage 2.
* This should now allow for tweaking of gravity speed and player speed
without breaking all actor collision checking.
2019-07-17 04:07:38 +00:00
|
|
|
if (direction === "left") {
|
|
|
|
if (doodadSize - e.Overlap.X < thickness) {
|
|
|
|
// Touching the right edge, open the door.
|
|
|
|
opened = true;
|
|
|
|
Self.PlayAnimation("open", null);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (e.Overlap.W === doodadSize - thickness) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (direction === "right") {
|
|
|
|
if (e.Overlap.X > 0) {
|
|
|
|
return false;
|
|
|
|
} else if (e.Settled) {
|
|
|
|
opened = true;
|
|
|
|
Self.PlayAnimation("open", null);
|
|
|
|
}
|
|
|
|
} else if (direction === "up") {
|
|
|
|
if (doodadSize - e.Overlap.Y < thickness) {
|
|
|
|
// Touching the bottom edge, open the door.
|
|
|
|
opened = true;
|
|
|
|
Self.PlayAnimation("open", null);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (e.Overlap.H === doodadSize - thickness) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (direction === "down") {
|
|
|
|
if (e.Overlap.Y > 0) {
|
|
|
|
return false;
|
|
|
|
} else if (e.Settled) {
|
|
|
|
opened = true;
|
|
|
|
Self.PlayAnimation("open", null);
|
|
|
|
}
|
2019-07-05 22:02:22 +00:00
|
|
|
}
|
Improve Collision Detection: More Active w/ Actors
* Improve the collision detection algorithm so that Actor OnCollide
scripts get called more often WHILE an actor is moving, to prevent a
fast-moving actor from zipping right through the "solid" hitbox and
not giving the subject actor time to protest the movement.
* It's implemented by adding a `Settled` boolean to the OnCollide event
object. When the game is testing out movement, Settled=false to give
the actor a chance to say "I'm solid!" and have the moving party be
stopped early.
* After all this is done, for any pair of actors still with overlapping
hitboxes, OnCollide is called one last time with Settled=true. This is
when the actor should run its actions (like publishing messages to
other actors, changing state as in a trapdoor, etc.)
* The new collision detection algorithm works as follows:
* Stage 1 is the same as before, all mobile actors are moved and
tested against level geometry. They record their Original and New
position during this phase.
* Stage 2 is where we re-run that movement but ping actors being
intersected each step of the way. We trace the steps between
Original and New position, test OnCollide handler, and if it returns
false we move the mobile actor to the Last Good Position along the
trace.
* Stage 3 we run the final OnCollide(Settled=true) to let actors run
actions they wanted to for their collide handler, WITHOUT spamming
those actions during Stage 2.
* This should now allow for tweaking of gravity speed and player speed
without breaking all actor collision checking.
2019-07-17 04:07:38 +00:00
|
|
|
|
|
|
|
return true;
|
2019-07-05 22:02:22 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-01-17 04:09:27 +00:00
|
|
|
Events.OnLeave(() => {
|
2019-07-05 22:02:22 +00:00
|
|
|
if (opened) {
|
2022-01-17 04:09:27 +00:00
|
|
|
Self.PlayAnimation("close", () => {
|
2019-07-05 22:02:22 +00:00
|
|
|
opened = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|