Try my new website:
www.urcho.com
- the new SIMPLE social network
Sign up
|
284
members |
114
snippets
Search for:
ALL
POPULAR
File Controls
Multiplayer Code
2D Effects
3D Effects
Oldskool demos
Basic Functions
Maths/Physics
Sound
Tutorials
Misc
Username:
Password:
Sign up
See if an Entity is in View by Berbank
[
back
]
Author:
Archive
| Viewed:
535
times | Language:
BlitzBasic 3D
| Category:
Maths/Physics
Function InView(a,b,Angle#=90,range#=10000) ; a is the entity looking ; b is the entity being looked for ; Angle# is the view angle in degrees. ; range is the distance the entity can see If EntityDistance(a,b) > range# Then Return False dx# = EntityX(a,1) - EntityX(b,1) dz# = EntityZ(a,1) - EntityZ(b,1) TFormNormal dx#,0,dz#,0,0 nx# = TFormedX() nz# = TFormedZ() TFormNormal 0,0,1,a,0 hx# = TFormedX() hz# = TFormedZ() dot# = (nx# * hx#) + (nz# * hz#) If ACos(dot#) < (180 - (Angle#/2)) Return False Else Return True EndIf End Function
Author Comments:
Havent properly checked this yet, but it seems to work. There are other code fragments out there that do similar things but couldnt find anything that did this in such a specific way. Simply use like this: If InView(EntityA,EntityB,ViewAngle,RangeValue) debuglog("A can see B) else debuglog("A cant see B) endif This is for 2D worlds and make sure the objects have zero pitch and Roll (are not rotated on the X or Z axis). Does not take into account occluding objects.
Login or
create an account
to comment on this snippet