Skip to content

Any good method to determine current player is standing on sth.? #1068

Answered by AlmasB
chengenzhao asked this question in Q&A
Discussion options

You must be logged in to vote

Hi,

If the entity in question uses PhysicsComponent, then you can add a ground sensor:

private Entity createPlayer(double x, double y, double width, double height) {
PhysicsComponent physics = new PhysicsComponent();
physics.addGroundSensor(new HitBox(new Point2D(5, height - 5), BoundingShape.box(width - 10, 10)));
physics.setBodyType(BodyType.DYNAMIC);

Then check:

player.getComponent(PhysicsComponent.class).onGroundProperty().addListener((o, oldValue, newValue) …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by chengenzhao
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants