Lineofsight3d help

Blitz3D Forums/Blitz3D Programming/Lineofsight3d help

Ah, I think it's because you are using the sphere picking mode for the enemy. And unlike polygon picking mode, it will compute a pick even if the linepick is done from inside the sphere and out. To avoid it you can offset the linepick from the enemy first.

Try with this version:
Function LineOfSight3D(observer,target,viewrange#=10.0,viewangle# = 90.0,offset#=1.0)

	;distance between observer and target
	Local dist# = EntityDistance(observer,target)

	;check if the target is within viewrange 
	If dist<=viewrange
		
		;observer vector
		TFormVector 0,0,1,observer,0
		Local ox# = TFormedX()
		Local oy# = TFormedY()
		Local oz# = TFormedZ()
	
		;pick vector
		Local dx# = (EntityX(target,True)-EntityX(observer,True))/dist#
		Local dy# = (EntityY(target,True)-EntityY(observer,True))/dist#
		Local dz# = (EntityZ(target,True)-EntityZ(observer,True))/dist#

		;dot product
		Local dot# = ox*dx + oy*dy + oz*dz

		;check if the target is within the viewangle
		If dot => Cos(viewangle/2.0)
			; check if something is blocking the view
			If LinePick(EntityX(observer,True)+dx*offset,EntityY(observer,True)+dy*offset,EntityZ(observer,True)+dz*offset,dx*viewrange,dy*viewrange,dz*viewrange,0.01)=target
				; observer can see target
				Return True
			End If
		End If
		
	End If

	; observer cannot see target	
	Return False

End Function

And set the offset parameter so it is larger than the radius of the enemy... That should work. I think :)