Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / casting triangle ray in front of enemy npc??

Author
Message
David iz cool
20
Years of Service
User Offline
Joined: 21st Sep 2005
Location: somewhere lol :P
Posted: 10th Aug 2010 16:38
how do u cast a triangle ray in front of your enemy npc so if u get inside the triangle he can see you. otherwise he cant????

Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 10th Aug 2010 16:46 Edited at: 10th Aug 2010 16:51
Most people would just check the angle - like work out the difference on X and Z between the enemy and player, then deduct the enemy angle. With that, you can tell if the player is within the arc.

Something like...

obj_e=10 `Enemy
obj_p=15 `Player
DX#=object position x(obj_e)-object position x(obj_p)
DZ#=object position z(obj_e)-object position z(obj_p)
D#=sqrt((dx#*dx#)+(dz#*dz#))

So that provides the distances and overal 2D distance between the objects in D#

Now the angle...
A#=wrapvalue(atanfull(DX#,DY#)-object angle Y(obj_e))

Now take that angle and make it unsigned...
If A#>180 then dec A#,360.0

So now its within -180 to 180 - but more useful is that it's the difference between the player and enemy. Now you can do an easy condition, like IF D#<100 and A#>-45 and A#<45 then SPOTTED!

Also, it's quite cool to do an actual visibility check - so pick a random limb on your player model if you have one, or alternatively pick a coordinate around the camera, as if the camera is a head and your picking locations inside it. Anyhoo, with that - do a line intersection check between this location and the enemies eyes, head, whatever you can use that's a limb. With that, you can make it possible to hide behind walls etc - and because you check a random spot, you can get spotted with just your toes sticking out, or if you peek around at the wrong time. This provides a bit of randomness to it - if your out in the open then you'll be spotted, but if your quick and you find good cover, it is possible to get away with it. Just something that I added the last time I did this, and it made a huge difference, made it much more fair.

Health, Ammo, and bacon and eggs!
David iz cool
20
Years of Service
User Offline
Joined: 21st Sep 2005
Location: somewhere lol :P
Posted: 10th Aug 2010 20:34
thankyou very much van! i really appreciate it!


offtopic but did u ever finish your terrain editor? just curious

Login to post a reply

Server time is: 2026-07-25 23:12:12
Your offset time is: 2026-07-25 23:12:12