schteppe / p2.js

JavaScript 2D physics library
Other
2.64k stars 330 forks source link

body position won't go > 50 #190

Closed chrisid closed 8 years ago

chrisid commented 8 years ago

Probably not an engine issue, but as I am moving from Box2D to this, can't realise what's wrong.

There's a keyboard press event that sets: body.velocity[0] = 20;

when the body.position[0] reaches 50:

any thoughts?

this is my base setup:

world = new p2.World({ gravity:[0, 0] });

body = new p2.Body({
        mass: 1,
        fixedRotation: true,
        gravityScale: 0,
        velocity: [0, 0],
        position: [0, 0]
    });
shape = new p2.Box({ width: 20, height: 20 });

body.addShape(shape);
world.addBody(body);

function render(){
    console.log(body.position + "  |  v:  " + body.velocity);
}

function update(t){
    requestAnimFrame(update);
    var dt = t !== undefined && lastTime !== undefined ? t / 1000 - lastTime : 0;
    world.step(timeStep, dt, maxSubSteps);
    render();
    lastTime = t / 1000;
}
schteppe commented 8 years ago

Sounds like you hit an invisible object? Maybe you can debug using the beginContact event?

Haven't tested your code snippet yet but I'm pretty sure the body should continue beyond 50..

schteppe commented 8 years ago

@chrisid Here's a JSFiddle running your code, with slight modification. The body does not stop at 50.

schteppe commented 8 years ago

@chrisid did you get this problem resolved?