Angle based bounce

Blitz3D Forums/Blitz3D Programming/Angle based bounce

I have a sphere which is moving at an angle towards a wall, when it hits the wall I need to know what the deflection angle will be in order to turn the Entity.

Any help would be greatfully appreciated.

if your walls are 'straight' you can use this,

with xi,yi,zi being the current inertia of the ball when it hits.

nx=collidedNx()
ny=collidedny()
nz=collidedNz() ;get the normals

if nx<>0 xi=-xi
if ny<>0 yi=-yi
if nz<>0 zi=-zi
;-

you could try nx=abs(collidednX())*x etc, for non straight angles.

Thanks for the quick response, but it didn't seem to work, let me elaborate a little, my ball object is being moved by:

MoveEntity balls(1)\obj,0,0,balls(1)\speed

then all I have to do to change its direction is to use:

TurnEntity balls(1)\obj,0,newAngle,0

I then check for collisions using:

Collisions SPHERE, POLY,2,2
CountColl = CountCollisions(balls(1)\obj)
If CountColl<>0 Then
For f=1 To countColl
If EntityCollided(balls(1)\obj,ground) Then
TurnEntity balls(1)\obj,0,bouncedAngle,0
End If
Next
End If

Its the bouncedAngle that I cannot get right.

bouncedAngle = ATan2(CollisionNX(balls(1),f),CollisionNZ(balls(1),f)) + offset


play with the offset, and the order of the arguments passed to ATan2, and the signs

With a little tweaking it worked, thatnks for your help.

the angle of incident = the angle of attack......