I am trying to create a physics engine for my game, and need to cancel out any lateral velocity for when entities turn. I have tried to mimic this page's example, but it is not working. I have objects sliding sideways, as if they continued to have no friction.
Could you please check my friction equation below and make sure I have the proper variables plugged into the right places? If everything checks out I can do some more intensive debugging.
Vector2d lateralnormalized = new Vector2d(1, new Angle(heading)); lateralnormalized.invert(); double dot = Vector2d.dotProduct(lateralnormalized, velocityvector); Vector2d lateralvelocity = new Vector2d(lateralnormalized); lateralvelocity.multiplyInline(dot); // Multiply by mass to get impulse lateralvelocity.multiplyInline(-1 * getMass()); applyImpulse(new Vector3d(lateralvelocity));
Vector2d(int, Angle) creates a new vector of magnitude
int at angle
Vector2d.invert() rotates the vector pi/2 radians (90 degrees).