Entity Picking

Blitz3D Forums/Blitz3D Programming/Entity Picking

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Could somebody please show me how to test if an entity was picked? I'm using this:

;test dummy

dummy = CreateCube()
ScaleEntity dummy,100,100,100
EntityPickMode dummy,3,True
PositionEntity dummy,1,-10,1
EntityColor dummy,0,0,255

.....

If MouseDown (1) Or JoyDown (1)

PickedEntity = CameraPick (camera, MouseX (), MouseY ())

;if we are picking

If PickedEntity

If PickedEntity = dummy

FreeEntity dummy

EndIf

CreateFlame (PickedX (), PickedY (), PickedZ (), fire)


EndIf

EndIf

I suggest you use this code starting after the If MouseDown(1) or Joydown(1)

CameraPick(camera, mousex(), mousey())
If PickedEntity() = dummy then freeentity dummy : CreateFlame(pickedx(), pickedy(), pickedz(), fire)

I hope you add more than just one dummy box to your game ;) And also if you have a low poly mesh you want to pick then make sure that you use EntityPickMode dummy,2

Thanks. I've been messing around with entity picking a I've come up with some cool stuff. I saw an example in the blitz programs and that explanned alot :). Oh and don't wory, the dummy was just a test;I will have alot of objects to shoot at :). Here is the code I came up with:

Function CheckPicking()

If MouseDown(1)

CameraPick(cam1,MouseX(),MouseY())

If terrain = CameraPick(cam1,MouseX(),MouseY())

CreateExplosion(PickedX(),PickedY(),PickedZ(),0)

ElseIf water = CameraPick(cam1,MouseX(),MouseY())

CreateExplosion3D(PickedX(),PickedY(),PickedZ (),1,200,230,255,False,water_sprite)

EndIf

EndIf

End Function

Note. "CreateExplosion" and "CreateExplosion3D" are just functions I made.

Wow that's a lotta pickinz

Here's a better way ;)

Function CheckPicking()

If MouseDown(1)

CameraPick(cam1,MouseX(),MouseY())

If terrain = PickedEntity()

CreateExplosion(PickedX(),PickedY(),PickedZ(),0)

ElseIf water = PickedEntity()

CreateExplosion3D(PickedX(),PickedY(),PickedZ (),1,200,230,255,False,water_sprite)

EndIf

EndIf

End Function


or

This checks if there's a picked entity and THEN does the other If's
Function CheckPicking()
	If MouseDown(1)
	
		CameraPick(cam1,MouseX(),MouseY())
			If PickedEntity() <> 0
				If terrain = PickedEntity()
					CreateExplosion(PickedX(),PickedY(),PickedZ(),0)
					
					ElseIf water = PickedEntity()
					
					CreateExplosion3D(PickedX(),PickedY(),PickedZ (),1,200,230,255,False,water_sprite)
				EndIf
			EndIf
	
	EndIf
End Function


I tried that but It didn't work out to well. :(

Debuglog different variables (like:
Function CheckPicking()
If MouseDown(1)

CameraPick(cam1,MouseX(),MouseY())
debuglog "terrain:"+terrain+", water:"+water+"pickedEntity:"+PickedEntity()
If PickedEntity() <> 0

[/code]
Then go debugging, and see if you actually pick anything... and where the problem lies.