Hello Devs,
I felt like sharing something which I struggled with a lot. I wanted to apply impulse on a rectangular cube at a specific position. Of course, you can use absolute position to make it work like this,
let absoluteRelativePoint = new Vec3(0.5,0.0,0.0); //rightmost side of the cube in absolute terms
this.rigidbody.applyImpulse(impulse,absoluteRelativePoint);
but this is wrong. The object won’t rotate if you have impulse = Vec3(magnitude, 0.0,0.0);
The function applyImpulse
expects relativePoint param to be in world space without translation. Something like this,
let absoluteRelativePoint = new Vec3(0.5,0.0,0.0); //rightmost side of the cube in absolute terms
let worldSpaceRP = absoluteRelativePoint.transformMat4(this.node.getWorldRS()); //rotating and scaling relative point to node space(local space), ignoring translation
this.rigidbody.applyImpulse(impulse,worldSpaceRP);
and that’s it. You will get the right behaviour when you will apply impulses or forces on different point of an object.
Thanks.