Linepick command

Blitz3D Forums/Blitz3D Programming/Linepick command

Ash_UK(Posted 2003) [#1]
Hi guys, can anyone please tell me how to use the linepick command, maybe a small piece of example code?
You see the reason is, i want to be able to use linepick to see if the moving platform is below my character, and if so to drop my character on the platform (To stop him falling through it) as you can't use the standard collision commands for for moving entities.

Thanks very much for any help

BLUE


EOF(Posted 2003) [#2]
Not my code. It's quite big as well.
If you can hack your way through it may help:
Graphics3D 640,480 
SetBuffer BackBuffer() 

camera=CreateCamera()
light=CreateLight() 

PositionEntity camera,0,1000,0
CameraRange camera,950,1050
CameraZoom camera,75 ; eliminate perspective

Local hit1$,hit2$, rad#=0,dist#=5,mode=1

c2=CreateSphere() 
EntityColor c2,255,50,50 : EntityAlpha c2,0.7
PositionEntity c2,0,0,0 
PointEntity camera,c2 
EntityRadius c2,1 
c3=CreateSphere() 
EntityColor c3,0,0,255 : EntityAlpha c3,0.7
pickLine=CreateCylinder(16,True,c3) ; The pickline radius
RotateMesh pickline,-90,0,0
EntityColor pickLine,255,255,0 : EntityAlpha pickline,0.6
distline=CreateCylinder(8,True,c3) ; The distance line
RotateMesh distline,-90,0,0
EntityColor distline,0,255,0

y#=0

While Not KeyDown( 1 ) 

hit1$="" 
hit2$="" 

If KeyHit(57) Then mode=(mode+1) Mod 3 :; space changes pickmode (none,sphere,poly)
EntityPickMode c2,mode

x#=x+(KeyDown(205)-KeyDown(203))*0.1 ; Left/Right arrow Alters X
z#=z+(KeyDown(200)-KeyDown(208))*0.1 ; Up/Down arrow Alters Z
rad=rad+(KeyHit(210)-KeyHit(211))*0.1 ; Insert/Delete alters radius
dist=dist+(KeyHit(199)-KeyHit(207))*0.1 ; Home/End alters distance

PositionEntity c3,x,y,z
ScaleEntity pickLine,rad,rad,dist/2
PositionEntity pickLine,0,0,rad+dist/2
ScaleEntity distline,0.1,0.1,dist/2
PositionEntity distline,0,0,dist/2

If EntityPick(c3,dist#)<>0 Then hit1$="Entitypick found entity"
If LinePick(x#,y#,z#,0,0,dist#,rad#)<>0 Then hit2$="Linepick found entity" 

UpdateWorld
RenderWorld 
Color 255,255,255
Text 0,0,"X:"+EntityX(c3)+" Y:"+EntityY(c3)+" Z:"+EntityZ(c3)+" Pick:"+mode+" Dist:"+dist+" Radius:"+rad
Text 0,15,"Arrow keys to move, Insert/Delete alters Radius, Home/End alters pick distance, Spacebar changes pick mode"
Color 0,255,0
Text 0,30,hit1$
Color 255,255,0 
Text 0,50,hit2$ 

Flip 

Wend 
End 



Ziltch(Posted 2003) [#3]
I found that linepick sometimes picked the source entity. This was creating rare strange bugs, that took a while to find the reason.

To get around this problem if you face it, is to hide the source entity before the linepick and do a showentity afterwards. You should only ever have to do this if the source entity is pickable.