If you want to stick with your collision algorithm there, then here are some tips on how you can speed things up.
- Do some distance checks between the player and the level. If the player is far from the chunks of the level, then you can skip the collision check.
Pseudocode:
If CalcDistance(Player1, Object2) > Furthest Distance
Skip Collision
Else
Do Collision
EndIf
Function CalcDistance(Player1, Object2)
X1#=Object Position X(Player1) : X2#=Object Position X(Object2)
Y1#=Object Position Y(Player1) : Y2#=Object Position Y(Object2)
Z1#=Object Position Z(Player1) : Z2#=Object Position Z(Object2)
Dist# = SQRT( (X2#-X1#)^2 + (Y2#-Y1#)^2 + (Z2#-Z1#)^2 )
EndFunction Dist#
- And again, since the SQRT command is an iteration function, it tends to be expensive to calculate. So instead, try squaring the equation, and check for then "Squared-Furthest-Distance" instead.
- Try hiding objects that are not in view.
But there are always other alternatives like using NGCollision DLL, it works quite fast. Hope that helps.
AsriCE Crew,
- Adi
There's only one hope.