piqnt / planck.js

2D JavaScript Physics Engine
http://piqnt.com/planck.js/
MIT License
4.87k stars 236 forks source link

DistanceJoint `getReactionForce` function not working #275

Open quinton-ashley opened 5 months ago

quinton-ashley commented 5 months ago

I get an error when using getReactionForce with distance joints because this.m_u is undefined

/**
 * Get the reaction force on bodyB at the joint anchor in Newtons.
 */
DistanceJoint.prototype.getReactionForce = function (inv_dt) {
    return Vec2.mulNumVec2(this.m_impulse, this.m_u).mul(inv_dt);
};
quinton-ashley commented 5 months ago

Also these functions need a timeStamp as input (I think) which could be better documented.

image

quinton-ashley commented 5 months ago

p5play discord user @ metamere said that the .initVelocityConstraints(step) function needed to be run

shakiba commented 5 months ago

I guess we need to initialize m_u to zero so that getReactionForce returns zero before the joint is activated. @zOadT what do you think?

Thanks for the feedback for the doc, I will update it.

zOadT commented 5 months ago

Hey! Haven't looked too much into it, but I also think initialising m_u to zero should be fine and reflect what the C code does. Maybe we also should do this for other Vec2 etc properties? Later we could think about whether we want to reuse the vector instead of reassigning a newly created one or if we want to keep the vector constant.