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.

Code Snippets / Object Distance function(usefull for beginners)

Author
Message
Yian
21
Years of Service
User Offline
Joined: 16th Jun 2003
Location: Nicosia, Cyprus(the Greek half)
Posted: 7th Sep 2003 20:07
Below is a function which calculates the distance between two objects.You can use it to make for example a monster attack you depending on how close you are.It is generally for beginners and uses pythagoras' theorem.

function distance(obj1,obj2)
dist=sqrt(((object position x(obj1)-object position x(obj2))*(object position x(obj1)-object position x(obj2)))+((object position z(obj1)-object position z(obj2))*(object position z(obj1)-object position z(obj2))))
endfunction dist

-john D.
spooky
22
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 7th Sep 2003 22:38
Unfortunately your code does not allow for objects at different heights (y axis).

Do a search on this forum and various functions are presented but best, and fastest is Pneumatic's which can be found here:

http://www.thegamecreators.com/?m=forum_view&t=11638&b=1

It uses those horrible vector commands but it is much faster than using sqrt.

The programmer formerly known as sonic
Yian
21
Years of Service
User Offline
Joined: 16th Jun 2003
Location: Nicosia, Cyprus(the Greek half)
Posted: 8th Sep 2003 01:43
i never got the hang of vector 3 stuff

-john D.

Login to post a reply

Server time is: 2024-11-24 01:56:33
Your offset time is: 2024-11-24 01:56:33