I've got a question for all the math/trig geniuses.
I am attempting to achieve an accurate reflection of velocity when my pawn contacts a surface (angled surfaces included).
I am getting the normal of what i contact.
set the new velocity variables to use when getting the angle..
Code:
veloX = Velocity.X;
veloZ = Velocity.Z;
then I'm converting my velocity to an angle in radians, and then converting that to degrees(for testing)..
Code:
angleInRadians = atan2 (veloZ, veloX);
angleInDegrees = angleInRadians * 180 / PI;
then multiplying the normal by 2 and subtracting the angle to get the new reflected angle and turn it back into a radian..
Code:
nAng = cNorm*2-angleInDegrees;
nRad = nAng*PI/180;
I can not find a way to convert radians back into velocity.. so I am trying to get the new reflected velocity from the angle in degrees..
Code:
V = Sqrt((veloX*veloX)+(veloZ*veloZ));
velocx= cos(nAng)*V;
velocZ = Sqrt((V*V)-(veloX*veloX));
Finally I set the pawns velocity to equal the new reflected velocity.
Code:
Velocity.Z=velocZ;
Velocity.X=velocX;
I am doing something wrong and often get sporadic results..if anyone sees where I am going astray please help by pointing it out or how I should go about doing it.
thank you,
-Dying
Bookmarks