# Lateral Friction Phisics

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 Angle.

Vector2d.invert() rotates the vector pi/2 radians (90 degrees).

• Don't do anything with angles. In general, if you use angles in physics for anything other than displaying things to the user, you are going to have problems. What is wrong with Vector2d lateral = velocity; lateral.normalizeInline()? – user41442 Feb 6 '14 at 21:07
• The heading is independent of the velocity. The entity could be pointing north, but moving north-east. – Yos233 Feb 6 '14 at 21:17
• I meant velocityDesired, sorry. The heading is still a vector. Using angles for representing directions is ... problematic, at best. Also we aren't going to debug your code for you, as this wouldn't help anyone else. Is there something about the equations you don't understand? – user41442 Feb 6 '14 at 21:24
• I do not have a desired velocity. I have the heading an object is pointing, and it's current velocity. I could not just rotate the velocityvector to match the heading, that would not be physically accurate. ---- While the heading could be a vector, I think it is easier to keep it as an angle, then convert it to a normalized vector on demand. If I do not use angles, how would you suggest I rotate the heading of an object 45 degrees? How would I calculate how much force to apply to each axis as a result of engine thrust? – Yos233 Feb 6 '14 at 21:37
• I do not understand why the impulse I apply to my object does not cancel its lateral velocity. I'm looking for an overview of my code, to help me see if I misplaced a variable. If code help belongs on StackOverflow only, I'll gladly ask it there. – Yos233 Feb 6 '14 at 21:39