Entity near? how?

Blitz3D Forums/Blitz3D Beginners Area/Entity near? how?

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.

depends how you define "near". There is the entitydistance command, so, this is possible:


Function EntityNear(Entity1, Entity2, Distance#= 2)
;"Distance#=2" mean that the default distance to check
; for is 2, so if you wanted 2 to be your default, and be
; able to change it, do this

If EntityDistance(Entity1, Entity2) > Distance# then
;If your entity distances are further than your designated "near" variable, then do nothing
EndIf

If EntityDistance(Entity1, Entity2) =< Distance# then
Return True
EndIf

End Function



This function would be used in code like:
If EntityNear(Zombie, Building) = True Then
;such and such
Endif

;OR

If EntityNear(Zombie, Building, 10) = True Then
;If the zombie is 10 units or less from the building then such and such
Endif



FURTHERMORE

If you need the distance in just X and Z (Y messed me up for a few things, say, a building's pivot is halfway up it's height, the entitydistance will be thrown off), use the 2d distance formular like so:

Function distxz(entity1, entity2)
distx# = EntityX(entity1) - EntityX(entity2)
distz# = EntityZ(entity1) - EntityZ(entity2)
distxz# = Sqr(distx^2 + distz^2)
Return distxz#

End Function 


Hope I helped you!