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.

Newcomers DBPro Corner / Finding an enemy in a radius

Author
Message
z_man
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: Australia
Posted: 28th Apr 2007 00:31
Hi

I just need to know how I could find if an enemy is in a radius of the player, so I can speed up the game by deactivating those outside it.

Thanks!

~ z_man ~
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 28th Apr 2007 01:02
Hello z_man. You can do that if you find out the distance between both objects...

have a look in this example.


greetings



oh my god
z_man
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: Australia
Posted: 28th Apr 2007 06:13
Great! That works just fine!

Thanks!

~ z_man ~
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 30th Apr 2007 19:52
Get rid of the sqrt function, it'll slow the game down all by itself. For this particular case, you only need to compare distances to a range and don't need the actual distance itself. So instead of doing the square root, compare the squared distance with the range squared like this:

distancia# = (dx#*dx#)+(dz#*dz#)
if distancia# < 200*200


chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 1st May 2007 00:10
Hallo Phaelax it really works!! we learn a little bit every day ...thankyou very much !!

oh my god

Login to post a reply

Server time is: 2024-09-25 21:30:33
Your offset time is: 2024-09-25 21:30:33