Game Development Community

What does this projectile code mean?

by profmusic · in Torque Game Engine · 07/05/2008 (5:44 pm) · 2 replies

I am trying to edit the source code for the projectile. This code represents the bounce part, but I am not sure what all of these variables actually do. I am trying to add in a part where I can change the direction. How would I do that?
The code:

Point3F bounceVel = mCurrVelocity - rInfo.normal * (mDot( mCurrVelocity, rInfo.normal ) * 2.0);;

#1
07/05/2008 (7:20 pm)
There is a component of mCurrVelocity that is normal (perpendicular to) the contact surface.
The dot product of the mCurrVelocity and the normal vector is the magnitude of the normal component.

This code calculates the magnitude of this component and then does a vector subtraction of twice that vector component from the current velocity. (It reflects the normal velocity component back outward from the surface.) This is an inelastic collision: a bounce that doesn't lose the projectile any energy.
#2
07/06/2008 (5:46 pm)
Thanks. I was confused by mDot and didn't know that mCurrVelocity and rInfo.normal were vectors. Yeah, I am really new to source code editing. Thanks alot though.