collision normal for physics

Blitz3D Forums/Blitz3D Programming/collision normal for physics

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

http://www.blitzbasic.com/Community/posts.php?topic=34953

; If the entity collided with the level, make it bounce.
If Entity_Hit > 0

; Calculate bounce:

; Get the normal of the surface which the entity collided with.
Nx# = CollisionNX(ballpos, 1)
Ny# = CollisionNY(ballpos, 1)
Nz# = CollisionNZ(ballpos, 1)

; Compute the dot product of the entity's motion vector and the normal of the surface collided with.
VdotN# = Vx#*Nx# + Vy#*Ny# + Vz#*Nz#

; Calculate the normal force.
NFx# = -2.0 * Nx# * VdotN#
NFy# = -2.0 * Ny# * VdotN#
NFz# = -2.0 * Nz# * VdotN#

; Add the normal force to the direction vector.
Vx# = Vx# + NFx#
Vy# = Vy# + NFy#
Vz# = Vz# + NFz#

This might help a little