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 Discussion / is there a range command?

Author
Message
MoonSon
22
Years of Service
User Offline
Joined: 25th Feb 2003
Location:
Posted: 6th May 2003 15:15
I was wondering if there was a simple command in DB that deals with the distance from an object in 3D space. For example -

If object 1 is within object 2 range(distance) then do something....

Or is my code attached the only way of doing this?
GameKit
22
Years of Service
User Offline
Joined: 6th Mar 2003
Location: USA, Staring Blankly at a Computer
Posted: 6th May 2003 17:49
or... you could make a function like this...

function distance(obj1,obj2)
dist#=sqrt((object position x(obj1)-(object position x(obj2))^2+(object position y(obj1)-(object position y(obj2))^2+(object position z(obj1)-(object position z(obj2))^2)
endfuntion dist#

this will give you the distance between any two object... so you can say...

if distance(1,2)<5 then collision=1 else collision=0

...hope this helps...

Anyone Can Destroy...But Few Can Create...
MoonSon
22
Years of Service
User Offline
Joined: 25th Feb 2003
Location:
Posted: 6th May 2003 17:56
thanks i'll give it a go

Hell IVIonkey
22
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 6th May 2003 21:33
However, doing a square root command every cycle can slow your program down, especially if you need to check the distance for several objects. Try the distance-squared method.

dist# = (x2-x1)^2+(y2-y1)^2+(z2-z1)^2

and

if dist# < (5)^2

Login to post a reply

Server time is: 2025-05-17 16:29:08
Your offset time is: 2025-05-17 16:29:08