Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix firing ChangeListener on onGroundProperty() with setScaleX() #775

Open
monjasa opened this issue Mar 25, 2020 · 2 comments
Open

Fix firing ChangeListener on onGroundProperty() with setScaleX() #775

monjasa opened this issue Mar 25, 2020 · 2 comments
Assignees

Comments

@monjasa
Copy link

monjasa commented Mar 25, 2020

It seems like chaning X scale (it doesn't matter whether the change includes sign change such as from +1 to -1, it still apears, for instance, from +1 to +0.5) invokes a shift of PhysicsComponent's onGroundProperty.

@monjasa monjasa changed the title Fix firing ChangeListener with onGroundProperty() using set Fix firing ChangeListener on onGroundProperty() with setScaleX() Mar 25, 2020
@AlmasB
Copy link
Owner

AlmasB commented Mar 28, 2020

Changing the scale of an entity affects its physics shape, which in turn requires the physics world to re-create the fixtures used in collision checks. When previous fixtures are removed, the onGround property becomes false since there is no fixture. Then when a new fixture is created, this triggers the onGround property to become true. So this is not a bug per se.

The above re-creation is necessary since even with just scaleX = -1 asymmetric hitboxes will need to be recalculated.

I don't have a clean solution to this yet, so I'll need some time to think. Any ideas?

@monjasa
Copy link
Author

monjasa commented Mar 29, 2020

For my problem (exclude triggering with mirroring but keep with jumping) I've used a boolean variable . Inside jump() method I've got something like if (!jumping) jumping = true; if the entity isOnGround() (its physics component with a ground sensor), and then add new ChangeListener with overridden method:

public void changed(ObservableValue<? extends Boolean> observable, Boolean wasOnGround, Boolean isOnGround) {
    if (!isOnGround && wasOnGround && jumping) {
        System.out.println("jumping...");
    } else if (isOnGround && !wasOnGround && jumping) {
        System.out.println("on ground");
        jumping = false;
    }
}

I mean, maybe it's possible to add kind of 'lock'. But I guess it's neither thread-safe nor applicable without a loss of performance due to checking and saving such a variable.

@AlmasB AlmasB self-assigned this Jul 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants