Hi chaps. I'm trying to bounce my balls off walls. The code below (adapted from the archives) works perfectly for walls that are at right angles (0,90,180,270) but anything else and the ball just sticks to the wall. Can you see anything wrong with this code?
Local SpeedVectorLength# = Sqr(xvel*xvel + zvel*zvel) For Local i:Int = 1 To CountCollisions(mesh) Local myentity:TEntity = CollisionEntity(mesh, i) Select GetEntityType(myentity) Case CTYPE_WALL ' Get the normal of the surface which the entity collided with. Local Nx# = CollisionNX(mesh, i) Local Ny# = CollisionNY(mesh, i) Local Nz# = CollisionNZ(mesh, i) ' Compute the dot product of the entity's motion vector and the normal of the surface collided with. Local VdotN# = xvel*Nx# + yvel*Ny# + zvel*Nz# ' Calculate the normal force. Local NFx# = -2.0 * Nx# * VdotN# Local NFy# = -2.0 * Ny# * VdotN# Local NFz# = -2.0 * Nz# * VdotN# ' Add the normal force To the direction vector. xvel = (xvel + NFx#) * 0.6 ' 0.6 = Bounciness yvel = (yvel + NFy#) * 0.6 zvel = (zvel + NFz#) * 0.6 direction = ATan2(zvel, xvel) End Select Next