How to applyImpulse() by Angle

Hello, I need help with math (yet again). I have this snippet that I think applies an impulse going forward.


kartNode.getControl(RigidBodyControl.class).applyImpulse(kartNode.getControl(RigidBodyControl.class).getPhysicsRotation().getRotationColumn(0).normalize().mult(2f), Vector3f.ZERO);

What would that code look like if I wanted to take that forward direction and nudge it towards the left/right by a 45 degrees? Any links to posts that might help are greatly appreciated. Thanks for your time.

I really thing we should add documentation to getRotationColumn() that says “If you think you need to use this then you are probably incorrect.” It’s the long way to go to do a really simple thing.

getPhysicsRotation().getRotationColumn(0).normalize().mult(2f)

Is the same as:
getPhysicsRotation().mult(Vector3f.UNIT_X).mult(2)

…only this version is clearer to just about anyone as to what’s really going on. It also perhaps hints at a possible solution to your question. For example, what if you passed a different vector to that mult? (Is the 45 degree rotation thing a constant?)

I think maybe some of the tutorials mention getRotationColumn() and it would be really nice if we could carve those out with a rusty spoon.

I couldn’t figure it out. However I got some nice results with the following code:


bananaSplit = kartNode.getControl(RigidBodyControl.class).getPhysicsRotation().mult(Vector3f.UNIT_X);
bananaSplit.y += impulseAngle;// can be + or - for right or left, impulseAngle is 45 / 180f * FastMath.PI
kartNode.getControl(RigidBodyControl.class).applyTorqueImpulse(bananaSplit);

Well, if UNIT_X is looking directly ahead… then UNIT_X.add(0, 0, 1).normalize() would look 45 degrees right and so on.

Thanks for the help. I’m getting even better results with:


...
//one direction:
bananaSplit = kartNode.getControl(RigidBodyControl.class).getPhysicsRotation().mult(Vector3f.UNIT_Y);
kartNode.getControl(RigidBodyControl.class).applyTorqueImpulse(bananaSplit.normalize().mult(impulseAngle));
//opposite direction:
bananaSplit = kartNode.getControl(RigidBodyControl.class).getPhysicsRotation().mult(Vector3f.UNIT_Y);
bananaSplit.y *= -1f;
kartNode.getControl(RigidBodyControl.class).applyTorqueImpulse(bananaSplit.normalize().mult(impulseAngle));
...

Bullet is tough to work with :frowning: but hack by hack stuff can get done :slight_smile: