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 / Proximity and Position Problem

Author
Message
eek
20
Years of Service
User Offline
Joined: 26th Dec 2004
Location:
Posted: 13th Jul 2006 00:55
I am attempting to write something where if the player is within the proximity of a box and a key is hit, something will happen. For a real game example, it would be like a player walking up to a treasure chest/box/whatever and opening it by hitting a key. For now it is just primitives though.

Here is an example of what I have done:


Basically, it is supposed to print Blah! when you hit the return key and if you are within +2 or -2 of the box's X and Z positions. The proximity code was tested before with one box and it worked fine, but now it doesn't with multiple boxes and I believe it is because I can't store all 99 boxes X and Z positions in X2# and Z2#. Any help is appreciated!
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 13th Jul 2006 01:56
You need Dims.......


Dim X2#(89)
Dim Z2#(89)

`Position of boxes
For I = 11 to 99
X2#(I-10) = object position x(I)
Z2#(I-10) = object position z(I)
Next I

eek
20
Years of Service
User Offline
Joined: 26th Dec 2004
Location:
Posted: 13th Jul 2006 02:40 Edited at: 13th Jul 2006 02:41
Thanks Pincho.

I modified the code to store all the coordinates in an array and also changed the object numbers to avoid the I-10. Anyways, I got me the same result when I tested it, when enter is pressed it displays blah no matter where you are. Here's the code:



Basically I'm back to where I started except in my mind, it should work because it should store all 99 objects positions in the arrays...
Krilik
19
Years of Service
User Offline
Joined: 16th Mar 2006
Location: Arizona, USA
Posted: 13th Jul 2006 04:55
You have your If statement written wrong. Should look like this:



If you don't use an And between the X position checks and between the Z position checks the statement will always return true, because your player will always be either greater than or less than the object coordinates.

You also forgot to change the less than signs in the second X and Z check to greater than signs. Your code would only return false if your player was behind and to the right of the object.
eek
20
Years of Service
User Offline
Joined: 26th Dec 2004
Location:
Posted: 13th Jul 2006 05:31
Ya thanks much, just figured that out. I appreciate the help.

If anyones interested the fixed code:
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 30th Jul 2006 13:41
Or if you don't want arrays you could try this: The cubes were too small I'm not sure if it works.



Login to post a reply

Server time is: 2025-05-25 08:34:55
Your offset time is: 2025-05-25 08:34:55