Dmartin42
... ONLY jump if they have collision with an entity or a static collision box
Technically, that should never be the case because that would mean that the collision was not properly resolved previously and the entity would be stuck in a collision box.
I think what you might be looking for is something like: if the player is touching the ground or another entity.
Depending on how you configured your player's collision and size properties, you should be able to use the player's bounding box
if it's bigger than the collision box
and do as CalvinMT suggested. You can just use the PhysicsEngine
for this, too:
if(Game.getPhysicsEngine().collides(player.getBoundingBox())){
// allow jump
}
You can configure your player's collision and size properties like so:
player.setCollisionBoxHeight(collisionBoxHeight);
player.setCollisionBoxWidth(collisionBoxHeight);
player.setWidth(boundingBoxWidth);
player.setHeight(boundingBoxHeight);
Another option would be to write a custom class for your player that extends Creature
and uses annotations.
@EntityInfo(width = 16, height = 16)
@CollisionInfo(collision = true, collisionBoxHeight = 4, collisionBoxWidth = 8)
public class MyPlayer extends Creature{
...
}
Also, I highly recommend enabling some debug rendering if you're playing around with collision boxes
and bounding boxes
.
Go to the game.properties
file and set
dbg_debugEnabled=true
dbg_renderBoundingBoxes=true
dbg_renderCollisionBoxes=true