Entitycollided doesn't work!!!

Blitz3D Forums/Blitz3D Beginners Area/Entitycollided doesn't work!!!

I'm trying to make my first game in Blitz3d. The entitycollided statement doesn't work for the dimonds. Here is the code. Its kinda long.

Graphics3D 800,600,0,2
AppTitle "Ballbot"
SetBuffer BackBuffer()



;load textures
Global sand_tex = LoadTexture("sand_tex.png")
timeball_tex = LoadTexture("timebot_tex.png")
water_tex = LoadTexture("water_tex.jpg")
sky_tex = LoadTexture("sky1.jpg")

;create player
Global ball=CreateSphere(32)
RotateTexture timeball_tex,90
EntityTexture ball,timeball_tex
EntityType ball,1
ScaleEntity ball,.5,.5,.5
EntityRadius ball,.5


pivot = CreatePivot()

camera=CreateCamera(pivot)

light=CreateLight()
RotateEntity light,100,0,10


;create sky-sphere
sky = CreateSphere(64)
FlipMesh sky
RotateTexture sky_tex,180
EntityTexture sky,sky_tex
ScaleMesh sky,400,400,400



;create water reflection
waterreflect = CreateMirror()
PositionEntity waterreflect,0,-4,0

;create water
ScaleTexture water_tex,4,4
water = CreatePlane()
EntityTexture water,water_tex
PositionEntity water,0,-5,0
EntityAlpha water,.5

;create die cube
diecube = CreateCube(camera)
EntityColor diecube,0,0,0
EntityAlpha diecube,0

;variables
Local wx = 0
Local wz = 0


Global col_type_ball = 1
Global col_type_ground = 2
Global col_type_dimond = 3
Global plyface# = 0
Global plx# = 0
Global ply# = 7
Global plz# = 0
Global pldz# = .1
Global plxface# = 0
Global plzface# = 0
Global plxspeed# = 0
Global Level = 1
Global lives = 3
Global dimonds_left = 0
Global fall = 0
Global collision_count = 0
Global pldie = 0
Global dcubealpha# = 0

Collisions col_type_ball,col_type_ground,2,2
Collisions col_type_dimond,col_type_ball,2,2
;TYPES

Type block
	Field x#,y#,z#,typ,x1#,y1#,z1#,x2#,y2#,z2#,ent
End Type
readlevels()

Type dimonds
	Field x#,y#,z#,pic,tim
End Type

RotateEntity ball,plrot,plface,90 
PositionEntity ball,plx,plz,ply
MoveEntity camera,-plx,-plz+3,-ply-2
ScaleEntity diecube,2,2,2
FlipMesh diecube
MoveEntity diecube,0,0,-.9
;main loop
While Not KeyDown( 1 )
Cls

wx = wx + 1
wz = wz + 1
PositionEntity water,Sin(wx)*.6,Cos(wz)/10-3.7,Sin(wx)*.8
PositionEntity waterreflect,Sin(wx)*.6,Cos(wz)/10-3.7,Sin(wx)*.8

If pldie = 0 Then
gravity()
testkeys()
hitwater()
EndIf
playerdie()
update_dimonds()

RotateEntity ball,plxface,plyface,90+plzface
PositionEntity pivot,plx,plz-1,ply+5
PositionEntity ball,plx,plz,ply

EntityAlpha diecube,dcubealpha

UpdateWorld

If plz < -3.6 Then fall = 1
RenderWorld
;Text 1,1,"Alpha: "+dcubealpha+"  fall: "+fall+"  playerz: "+plz
Flip

Wend
End





Function readlevels()
	Select level
	Case 1
		file = ReadFile("level1.mp")
	End Select

	box = CreateCube()
	ScaleEntity box,.501,.501,.501
	PositionEntity box,0,-3.5,7
	TurnEntity box,0,0,0
	EntityTexture box,sand_tex
	dimond = LoadMesh("dimond.3ds")
	EntityAlpha dimond,.9
	EntityShininess dimond,1
	ScaleEntity dimond,.1,.1,.1
	PositionEntity dimond,0,0,0

	x = ReadInt(file)
	y = ReadInt(file)
	
	For a = 1 To y
		For b = 1 To x
			typ = ReadInt(file)
			If typ = 3 Then
				movx# = b
				movy# = a
			EndIf
			If typ = 2 Then
				t.dimonds = New dimonds
				t\x# = b
				t\y# = -a
				t\z# = -3
				t\pic = CopyEntity(dimond)
				PositionEntity t\pic,t\x,t\z,t\y
			EndIf
			If typ = 1 Or typ = 2 Or typ = 3 Or typ = 4 Then
				c.block = New block
				c\x# = b
				c\y# = -a
				c\z# = -3.5
				c\typ = typ
				c\ent = CopyEntity(box)
				PositionEntity c\ent,c\x,c\z,c\y
			EndIf	
		Next
	Next
	FreeEntity(box)
	FreeEntity(dimond)
	dimonds_left = ReadInt(file)
	For d.block = Each block
		d\x = d\x - movx#
		d\y = d\y + movy#+7
		PositionEntity d\ent,d\x,d\z,d\y
		EntityType d\ent,2
		

	Next
	For q.dimonds = Each dimonds
		q\x = q\x - movx#
		q\y = q\y + movy# + 7
		PositionEntity q\pic,q\x,q\z,q\y
		EntityType q\pic,3
		EntityRadius q\pic,.3
	Next
End Function



Function gravity()
		temp = 0
		If fall = 1 Then
			pldz# = pldz# - .004
			plz = plz + pldz
			temp = 1
		EndIf
		
		If Not EntityCollided(ball,2) Then
			If temp = 0 Then
				pldz# = pldz# - .004
				plz = plz + pldz
			EndIf
		EndIf
		
		If fall = 0 And EntityCollided(ball,2) Then
			pldz = 0
		EndIf
End Function


Function testkeys()

	If KeyDown(203)
		plyface = plyface + 2
	EndIf
	If KeyDown(205)
		plyface = plyface - 2
	EndIf
	If KeyDown(200)
		plxspeed = plxspeed + .3
	EndIf
	If plxspeed > 0 Then
		plxspeed = plxspeed -.02
	EndIf
	If plxspeed < 0 Then
		plxspeed = 0
	EndIf
	If plxspeed > 2 Then plxspeed = 2
	plxface = plxface + plxspeed
	
	plx = plx - (Cos(plyface-90)*plxspeed)/55
	ply = ply - (Sin(plyface-90)*plxspeed)/55
End Function


Function hitwater()
	If plz < -3.5 Then
		plz = -3.5
		pldz = 0
		pldie = 1
	EndIf
End Function


Function playerdie()
	If pldie = 1 Then
	plz = plz - .001
	dcubealpha = dcubealpha +.01
	If dcubealpha > 1 Then dcubealpha = 1
	EndIf
End Function


Function update_dimonds()
	For d.dimonds = Each dimonds
		TurnEntity d\pic,0,-2,0
		;dist# = Sqr((plx-EntityX(d\pic))^2+(ply-EntityY(d\pic))^2)
		If EntityCollided(d\pic,1) Then d\tim = 1  ;This part doesn't work!!!
		If d\tim => 1 Then
			MoveEntity d\pic,0,.01,0
			d\tim = d\tim + 1
		EndIf
		If d\tim > 50 Then
			FreeEntity(d\pic)
			Delete d.dimonds
		EndIf
		
	Next
End Function


The update dimonds function spins the dimonds and is supposed to make them rise into the air and disappear when you hit them.

Does anyone have any suggestions?

you have to first declare collisions between the entity types. Otherwise, collisions won't work. Not regular types, either.

I thought I did declare the collisions on the line after I declared all of the global variables. Did I declare the collisions right.

entitytype ball,col_type_ball

you have to apply the type to the entity before it will do anything.
Do the same sort of thing for each one.

I used that command on the thirteenth line of text so i am still confused.

Graphics3D 800,600,0,2
AppTitle "Ballbot"
SetBuffer BackBuffer()



;load textures
Global sand_tex = LoadTexture("sand_tex.png")
timeball_tex = LoadTexture("timebot_tex.png")
water_tex = LoadTexture("water_tex.jpg")
sky_tex = LoadTexture("sky1.jpg")

;create player
Global ball=CreateSphere(32)
RotateTexture timeball_tex,90
EntityTexture ball,timeball_tex
EntityType ball,1                       ;HERE
ScaleEntity ball,.5,.5,.5
EntityRadius ball,.5


I also declared the dimond as
EntityType q\pic,3
EntityRadius q\pic,.1


Check CountCollisions()

Good Idea

Collisions col_type_ball,col_type_ground,2,2
Collisions col_type_dimond,col_type_ball,2,2

you assign 1 (col_type_ball) to a ball, ok!
you assign col_type_dimon to dimonds, ok!

what about : col_type_ground?

does the water act as ground?

check that

Juan

The ground are the blocks that float on the water.
If you hit the water, then you die.
Sorry if it wasn't clear at first.

I fixed the problem.

I'm not sure how. Just a little messing around with the programming. Thanks to everyone that helped me!

My Problem is back.

I tried experimented a little and found out that the ball bounces off of the dimond if I switch the code around, but the dimond doesn't bounce off of the ball when I switch it back.

Collisions col_type_ball,col_type_dimond,2,2  ; makes the ball bounce off of the dimonds


Collisions col_type_dimond,col_type_ball,2,2  ; doesn't make the dimonds bounce off of the ball


I don't think that polygon to sphere collision is possible, only sphere to polygon.

There is no such collision type as polygon to sphere. As you already set entityradius on both entitytypes you should be using Sphere to sphere collisions. The moving entity should be stated first in the collisions command.


Collisions col_type_ball,col_type_dimond,1,2 ; makes the ball bounce off of the dimonds



How do I tell what dimond got hit?

see the commands

CountCollisions
EntityCollides
CollisionEntity

probably you have to loop over the list of diamonds lookin for the one that has collided with the type you are interested in...

Juan

When creating the diamond store the type handle in the entities name ..

			If typ = 2 Then
				t.dimonds = New dimonds
				t\x# = b
				t\y# = -a
				t\z# = -3
				t\pic = CopyEntity(dimond)
				NameEntity t\pic, Handle(t)
				PositionEntity t\pic,t\x,t\z,t\y
			EndIf


Then when you are checking the ball collisions ...

for c = 1 to countcollisions( Ball )
     ThisEntity = CollisionEntity( Ball, c )
     d.dimond = object.dimond( entityname( ThisEntity ) )
     if d <> null
         freentity d\pic
         delete d
         Dimonds_Left = Dimonds_Left - 1
     endif
next


Thanks for all of the help, but I gave up on the entity collided command and used the distance formula.

dist# = Sqr((x1-x2)^2+(y1-y2)^2+(z1-z2)^2)


The distance formula works fine for me.

Why re-invent the wheel, just use EntityDistance.

I had never heard of the command entitydistance. I'll try it.

Thanks