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

In the case of free fall movement, the change value of moving distance in the same time interval cannot be greater than 2, that is to say, it will change from free fall movement to uniform linear movement #105

Open
oxDesigner opened this issue Feb 23, 2020 · 1 comment

Comments

@oxDesigner
Copy link

In the case of free fall movement, the change value of moving distance in the same time interval cannot be greater than 2, that is to say, it will change from free fall movement to uniform linear movement

I want to know how to modify it

code:

const bodyDef = new b2BodyDef;
bodyDef.type = b2_dynamicBody;
bodyDef.position.Set(0, 4);
this.body = world.CreateBody(bodyDef);

const dynamicBox = new b2PolygonShape();
dynamicBox.SetAsBoxXY(0.1, 0.1);
var lastX = this.body.GetPosition().y;
setInterval(() => {
var X = this.body.GetPosition().y;

console.log(X - lastX);
lastX = X;

}, 1000 / 60)
const fixtureDef = new b2FixtureDef;
fixtureDef.shape = dynamicBox;
fixtureDef.density = 1;
fixtureDef.friction = 0.2;

this.body.CreateFixtureFromDef(fixtureDef);

@ljluestc
Copy link

ljluestc commented Jan 5, 2024


const bodyDef = new b2BodyDef;
bodyDef.type = b2_dynamicBody;
bodyDef.position.Set(0, 4);
this.body = world.CreateBody(bodyDef);

const dynamicBox = new b2PolygonShape();
dynamicBox.SetAsBoxXY(0.1, 0.1);

const fixtureDef = new b2FixtureDef;
fixtureDef.shape = dynamicBox;
fixtureDef.density = 1;
fixtureDef.friction = 0.2;
this.body.CreateFixtureFromDef(fixtureDef);

const maxFallSpeed = 2.0; // Maximum downward velocity (adjust as needed)

setInterval(() => {
    const velocity = this.body.GetLinearVelocity();
    if (velocity.y < -maxFallSpeed) {
        // Limit the downward velocity to the maximum
        velocity.y = -maxFallSpeed;
        this.body.SetLinearVelocity(velocity);
    }
}, 1000 / 60);

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