Rectangle Entity collison with a Block Entity #243
RyanAelen
started this conversation in
Show and tell
Replies: 1 comment 1 reply
-
Applied changes for the 2021.2022.4-SNAPSHOT @Override
public void onCollision(List<Collider> colliders) {
for (Collider collider : colliders
) {
if (collider instanceof IBlocks) {
var box = collider.getBoundingBox();
BoundingBox top = new BoundingBox(box.getMinX() + 2, box.getMinY(), box.getWidth() - 4, 2);
BoundingBox bottom = new BoundingBox(box.getMinX() + 2, box.getMaxY() - 2, box.getWidth() - 4, 2);
BoundingBox left = new BoundingBox(box.getMinX(), box.getMinY() + 2, 2, box.getHeight() - 8);
BoundingBox right = new BoundingBox(box.getMaxX() + 2, box.getMinY() + 2, 2, box.getHeight() - 8);
if (top.intersects(this.getBoundingBox())) {
setAnchorLocationY(box.getMinY() - getHeight());
// this.nullifySpeedInDirection(Direction.DOWN); // If you're using gravity.
grounded = true;
}
if (bottom.intersects(this.getBoundingBox())) {
setAnchorLocationY(box.getMaxY());
}
if (left.intersects(this.getBoundingBox())) {
setAnchorLocationX(box.getMinX() - getWidth());
}
if (right.intersects(this.getBoundingBox())) {
setAnchorLocationX(box.getMaxX());
}
}
}
}
Note: the Override for checkForCollisions is not necessary anymore |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Made basic implementation of a Sprite colliding with Wall/Floor/Ceiling and preventing it from moving into it.
2022-04-21.23-00-08-1.mp4
Have hide off-topic parts of the class
Beta Was this translation helpful? Give feedback.
All reactions