simple collision detection

Blitz3D Forums/Blitz3D Programming/simple collision detection

IKG(Posted 2007) [#1]
Hello! Currently working the SDK but that shouldn't matter. Anyway..

I'm not that experienced when it comes to collisions. I know how to set them up, and that's it.

I need to make a simple If statement that checks to see if two selected entities have collided; if so then a variable increases. I've used EntityCollided and CollisionEntity, and have failed both times :D

Thanks!


IKG(Posted 2007) [#2]
bump?


deps(Posted 2007) [#3]
People can probably help you more if you show them what you have at the moment. You said that you failed using EntityCollided and CollisionEntity but show the code you used and maybe people can see where you did what wrong.


Zmatrix(Posted 2007) [#4]
Youll need Collisions enabled to get entitycollided() to work,
heres some b3d code from the Samples (Paul Gerfen tutorials) *i dont have the Sdk
hacked up a bit,
If you need "no responce" collisions check the Code Archives.


;-------------------------------
Graphics3D 800,600

Const CUBE_COL=1
Const SPHERE_COL=2

SetBuffer BackBuffer()

camera=CreateCamera()
CameraViewport camera,0,0,800,600
PositionEntity camera,0,0,-5

light=CreateLight(1)

cube=CreateCube()
PositionEntity cube,0,-5,5
EntityColor cube,70,80,190
EntityType cube,CUBE_COL

cube2=CreateCube()
PositionEntity cube2,0,5,5
EntityColor cube2,70,80,190
EntityType cube2,CUBE_COL

sphere=CreateSphere(12)
PositionEntity sphere,0,0,5
EntityColor sphere,170,80,90
EntityType sphere,SPHERE_COL


Collisions SPHERE_COL,CUBE_COL,3,1
PointEntity sphere,cube
While Not KeyHit(1)

MoveEntity sphere,0,0,0.02

UpdateWorld
RenderWorld

If EntityCollided(cube,sphere_COL)

col=col+1

PointEntity sphere,cube2
MoveEntity sphere,0,0,0.02
EndIf

If EntityCollided(cube2,sphere_COL)

col=col+1

PointEntity sphere,cube
MoveEntity sphere,0,0,-0.02
EndIf


Text 10,80,"Sphere Collided "+col+" times !!"
Flip

Wend
End
;-------------------------

hope it helps,

Sam


IKG(Posted 2007) [#5]
Ahh see I was just using the entity names with the EntityCollided function. Thanks!