Collision problems

Blitz3D Forums/Blitz3D Beginners Area/Collision problems

ervin(Posted 2006) [#1]
Hi all.

I'm having a little problem with collisions.

A green cube spins in space, and using the arrow keys you can push up against it.
Collisions are happening as I can't walk through the cube, but I want the cube to turn red when I do collide with it.
I'm not sure why the call to EntityCollided isn't working.

Can someone please help?

Thanks for any suggestions.

Graphics3D 800,600,32,2
SetBuffer BackBuffer()

US=1
THEM=2

Collisions US,THEM,1,2
Collisions THEM,US,1,2

light=CreateLight()
RotateEntity light,90,0,0

camera_pivot=CreatePivot()
PositionEntity camera_pivot,0,0,0
EntityRadius camera_pivot,1.5
EntityType camera_pivot,US

camera=CreateCamera(camera_pivot)

cube=CreateCube()
PositionEntity cube,0,0,5
EntityColor cube,0,255,0
EntityRadius cube,1.5
EntityType cube,THEM

While Not KeyHit(1)
	If EntityCollided(cube,US) EntityColor cube,255,0,0

	If KeyDown(200) MoveEntity camera_pivot,0,0,0.1
	If KeyDown(208) MoveEntity camera_pivot,0,0,-0.1
	If KeyDown(203) TurnEntity camera_pivot,0,1,0
	If KeyDown(205) TurnEntity camera_pivot,0,-1,0

	TurnEntity cube,0.5,0.5,0.5

	UpdateWorld
	RenderWorld
	Flip
Wend



b32(Posted 2006) [#2]
it should be:
If EntityCollided(camera_pivot,THEM) EntityColor cube,255,0,0



ervin(Posted 2006) [#3]
Thanks bram32.

Unfortunately, this doesn't quite fix it.
If I have 2 cubes, both with an EntityType=THEM, colliding with either one will only colour the first cube red.


Ross C(Posted 2006) [#4]
The way the blitz collisions work, is that the colliding entity must be a moving one, and the entity your colliding into must be static, non moving. That said, your error seems to be in entity collided.

If EntityCollided(cube,US) EntityColor cube,255,0,0


The first parameter of the command is entity your wanting to check, which is the camera_pivot. The next parameter is the entity TYPE of collision. Which your wanting to check against the cube, which has THEM type. so:

If EntityCollided(camera_pivot,THEM) EntityColor cube,255,0,0



b32(Posted 2006) [#5]
Entitycollided returns a handle to the collided entity.
bump = EntityCollided(camera_pivot, THEM) 
If bump > 0 Then EntityColor bump,255,0,0



Ross C(Posted 2006) [#6]
I tried it over here too bram, Works fine. I'm started typing, went for summit to eat, forgot to click post. By the time i'd clicked post, you'd already said the answer :D


ervin(Posted 2006) [#7]
Excellent!
Thanks to both of you for your help - especially the tip about EntityCollided returning a handle.