Ok... Cube based sliding collision should be the EASIEST thing to do in DB/P but I can't figure it out. The code just doesn't want to co-operate, I must be doing SOMETHING wrong!
Function Char_Entity(Num)
Rem **Record Old Data**
X# = Object Position X(Num)
Y# = Object Position Y(Num)
Z# = Object Position Z(Num)
Rem **Handle Physics**
Y# = Y# - 10 : `Gravity
Rem **Handle Collision**
Extrude = 24 :`Extrude Amount
For Index = 1000 To Level_Info(6)
If Object Exist(Index)
Rem **Get Data**
Rem Center
X3 = Object Position X(Index)
Y3 = Object Position Y(Index)
Z3 = Object Position Z(Index)
Rem Corner 1
X1 = Object Position X(Index) + Extrude
Y1 = Object Position Y(Index) + Extrude
Z1 = Object Position Z(Index) + Extrude
Rem Corner 2
X2 = Object Position X(Index) - Extrude
Y2 = Object Position Y(Index) - Extrude
Z2 = Object Position Z(Index) - Extrude
CollType = 1
Rem Find Collision
If CollType = 1
If Y# > Y3 And Y# < Y1 Then Gosub Check_Y_1
If Y# < Y3 And Y# > Y2 Then Gosub Check_Y_2
If X# > X3 And X# < X1 Then Gosub Check_X_1
If X# < X3 And X# > X2 Then Gosub Check_X_2
If Z# > Z3 And Z# < Z1 Then Gosub Check_Z_1
If Z# < Z3 And Z# > Z2 Then Gosub Check_Z_2
EndIf
EndIf
Next Index
Rem **New Data**
Position Object Num,X#,Y#,Z#
ExitFunction
Check_X_1:
If Y# Y2 And Z# Z2
X# = X1 + 1
EndIf
Return
Check_X_2:
If Y# Y2 And Z# Z2
X# = X2 - 1
EndIf
Return
Check_Y_1:
If X# X2 And Z# Z2
Y# = Y1 + 1
EndIf
Return
Check_Y_2:
If X# X2 And Z# Z2
Y# = Y2 - 1
EndIf
Return
Check_Z_1:
If Y# Y2 And X# X2
Z# = Z1 + 1
EndIf
Return
Check_Z_2:
If Y# Y2 And X# X2
Z# = Z2 - 1
EndIf
Return
EndFunction
The thing is, the collision only works on the y... I can walk around on TOP of the objects pretty well, but I can walk through them from the side, and from the bottom.
Here's how it works:
The objects I am testing collision with are all 50x50x50
The charactor is a 50x50x50 model
Ok, the obvious way would be to test each corner of the charactor, but
to cut down on calculations, I have incorperated a cheap but effective trick.
I set the bounding box for the cubes to 74x74x74, instead of 50x50x50. This takes into account the player charactor's bulk WITHOUT the added calculations.
Now to test collision on the level, I only have to plug in one point get it?
But the output is all wrong, I can't figure out how to fix it. Any takers?
Alex Wanuch
aka rapscaLLion
Kousen Dev Progress >> Currently Working On Editors