Open oxDesigner opened 4 years ago
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);
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;
}, 1000 / 60) const fixtureDef = new b2FixtureDef; fixtureDef.shape = dynamicBox; fixtureDef.density = 1; fixtureDef.friction = 0.2;
this.body.CreateFixtureFromDef(fixtureDef);