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 / [DBP] Function: CheckObjectCollisionArea (Useful for getting distances between objects)

Author
Message
Seppuku Arts
Moderator
20
Years of Service
User Offline
Joined: 18th Aug 2004
Location: Cambridgeshire, England
Posted: 24th Dec 2008 17:22 Edited at: 29th Apr 2012 03:50
Hey guys, never submitted code snippets here, so now I thought I ought to.

What it will do is basically check if two objects are within a specified distance of each other it will return a value of 1. A simple way of checking things if you like. It might be useful if you want to only let the player talk to an NPC if they're within a certain distance or if you want an enemy to only follow you if you're close enough.

Just as an example: write (inside of a loop and with 2 available objects)

val = CheckObjectCollisionArea(1,2,35)
if val = 1 then text 0,10,"We are in distance."
if val = 0 then text 0,10,"You're too far away."



Oh and I made a pretty picture too, just to show it in use (you'll see in the debug data where it returns a '1'):



Sasuke
18
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 25th Dec 2008 01:22
One thing, wouldn't distance/dis and all the position varibles be floats? Then again, depending on the scale of everything it might not, but still, wouldn't it...

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Seppuku Arts
Moderator
20
Years of Service
User Offline
Joined: 18th Aug 2004
Location: Cambridgeshire, England
Posted: 25th Dec 2008 01:29
Ah sorry, I normally prefer to deal without them, just because they're easier on the eyes when looking at the data. (and the world scale I work with, they really don't make a difference for me) perhaps I should have thought about that, I'll edit those in when I check the forums again as I am about to leave.

--The hatred of those who harbour such ill feelings as, "He reviled me, assaulted me, vanquished me and robbed me," is never appeased.--
Mr Tank
22
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 25th Dec 2008 03:25
That's cool. It'd seem more symmetric with a cylindrical of spherical check. For instance...


That's cylindrical.

Merry Xmas.

Login to post a reply

Server time is: 2024-11-25 10:03:11
Your offset time is: 2024-11-25 10:03:11