3d collison help

Previous topic - Next topic

djtoon

hi
this is what im doing
Code (glbasic) Select

X_MAKE3D 0.1,800,45
X_CAMERA -220,-140,-400+pz,-220,-140,0+pz
X_FOG RGB(0,0,0),FALSE,350,480
X_CULLMODE 0
ALPHAMODE -1

X_SPOT_LT 1,RGB(255,255,255),-20,-140,-300+pz,0,0,800+pz,360



px=px+speedx
py=py+speedy

pz=pz+zspeed
X_MOVEMENT px,py,pz
X_DRAWOBJ 2,0

col=0
LOCAL colCount=0
FOR x=xjump TO xEnd STEP 1

X_MOVEMENT (blocx[x].x*40 )*-1,(blocx[x].y*40 )*-1,(blocx[x].z*40)
X_SETTEXTURE blocx[x].texture,0
X_DRAWOBJ blocx[x].model,0


  col=X_COLLISIONAABB( 2, 0, (blocx[x].x*40 )*-1,(blocx[x].y*40 )*-1,(blocx[x].z*40) , 40, 40, 40)



IF col=1
colCount=colCount+1

ENDIF

NEXT


for some reson i get hits on all the objects
why?


Slydog

#1
I can't follow the code.
In the middle it appears messed up, like some invalid ascii characters or something.
Try the [ CODE] [ /code] blocks to see if it helps.

From what is written in the FOR loop, in the loop code I see no mention of the 'x' variable so I don't know what this loop does.
Is 'object 2' larger than you expected?
Are you trying to draw multiple blocks of size (40,40,40) and checking if 'object 2' hit those blocks?

[Edit]  What does 'X_COLLISIONAABB()' return? 
Help says its a float but doesn't explain what it represents.  I would expect it to be an integer of TRUE or FALSE.
If it is, then you could change this:
Code (glbasic) Select
IF col=1
  colCount=colCount+1
ENDIF
to:
Code (glbasic) Select
INC colCount, col
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Hemlos

for the duration of any collision, you are incrementing the collision count, regardless if only one object collides.

Code (glbasic) Select
IF col=1
  colCount=colCount+1
ENDIF
Bing ChatGpt is pretty smart :O