This thing is really bugging me now, I have tried several methods to implement basic ball physics but to no avail. The damn thing just will not bounce. I know elasticity can never be > 100% (not in the real world at least), and that changing velocities along the collision normal is the standard way of implementing ball physics so why doesn't this code work? Any help would be appreciated.
Here is the code:
For c = 1 To CountCollisionsBlitz(ball\entity)
If CollisionHitTypeBlitz(ball\entity,c) = TYPE_WORLD Then
; get vector using collision normals
nx#=CollisionHitNormBlitz(ball\entity,c,1)
ny#=CollisionHitNormBlitz(ball\entity,c,2)
nz#=CollisionHitNormBlitz(ball\entity,c,3)
; get dot product of ball vector and normal vector
vDot#=((nx#*ball\velocity#[0]) + (ny#*ball\velocity#[1]) + (nz#*ball\velocity#[2]))
; factor in elasticity
vDot#=vDot#*(1+ball\elasticity#)
; set new velocity
ball\velocity#[0]=ball\velocity#[0]-(vDot#*nx#)
ball\velocity#[1]=ball\velocity#[1]-(vDot#*ny#)
ball\velocity#[2]=ball\velocity#[2]-(vDot#*nz#)
EndIf
Next
Here is the code:
For c = 1 To CountCollisionsBlitz(ball\entity)
If CollisionHitTypeBlitz(ball\entity,c) = TYPE_WORLD Then
; get vector using collision normals
nx#=CollisionHitNormBlitz(ball\entity,c,1)
ny#=CollisionHitNormBlitz(ball\entity,c,2)
nz#=CollisionHitNormBlitz(ball\entity,c,3)
; get dot product of ball vector and normal vector
vDot#=((nx#*ball\velocity#[0]) + (ny#*ball\velocity#[1]) + (nz#*ball\velocity#[2]))
; factor in elasticity
vDot#=vDot#*(1+ball\elasticity#)
; set new velocity
ball\velocity#[0]=ball\velocity#[0]-(vDot#*nx#)
ball\velocity#[1]=ball\velocity#[1]-(vDot#*ny#)
ball\velocity#[2]=ball\velocity#[2]-(vDot#*nz#)
EndIf
Next