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 / Simple collision not detected / What am I doing wrong?

Author
Message
047
18
Years of Service
User Offline
Joined: 4th Jun 2006
Location:
Posted: 30th Jul 2006 18:53
Ok, I posted a similar message on the newcomers forum but no one replied so I decided to try my luck here.
This is really driving my crazy as my program was almost complete but I saved the collisions for last and all my work will be useless I can figure out how to properly use collisions.
I created this short program to test and experiment with collisions:

make object sphere 1, 1
make object sphere 17, 1

set global collision off

set object collision on 1
set object collision on 17

set object collision to spheres 1
set object collision to spheres 17

position object 1, 0, 0, 10

a = -20

sync on
do
position object 17, a, 0, 10
if rightkey() = 1 then a = a + 1
if leftkey() = 1 then a = a - 1
set cursor 1,1: print object collision(1,17): print a
sync

loop

It should be very straight forward but somehow unless I use Global Collision On the collision goes undetected. Can anyone tell me what am I doing wrong?
In my real program I want to use this in a car game where the collision between the sphere object and a "track" object will determine whether the camera should move up or down to simulate uphill and downhill motion. I don't know what's wrong with the track object because even using Global Collision On I can't get the computer to detect any type of collision at all between sphere and track.
Any type of help or advise will be greatly appreaciated.
Thanks!!!
Krilik
19
Years of Service
User Offline
Joined: 16th Mar 2006
Location: Arizona, USA
Posted: 30th Jul 2006 19:41
By default all objects are included in collision. The set global collision and set object collision on are uneccessary. The program will run properly if you comment those lines out.
047
18
Years of Service
User Offline
Joined: 4th Jun 2006
Location:
Posted: 31st Jul 2006 00:55
I know that by default the Global Collision is set to ON. But because my program has many large graphics on screen at all times I needed to have the computer worry about only the two objects that matter in order to make the camera move up and down when needed. When the Global Collision is ON and the system has to calculate which objects' collisions to ignore and which ones to act upon my program literally stops running (it's actually running, but so slowly that feels like it had actually stopped).
Besides, if Global Collision needs to be On all the time what would be the purpose of the Set Object Collision command?

Thanks for taking time to reply and trying to help me!!
Krilik
19
Years of Service
User Offline
Joined: 16th Mar 2006
Location: Arizona, USA
Posted: 31st Jul 2006 02:24
Well I had the same problem with too many collision detections going on. So I began messing around with various collision commands and I came to the conclusion that Set Global Collision does not work properly. All it does is turn collision on or off, regardless of individual collision settings. To solve my problem all I did was turn collision off for objects I didn't want to check.

Instead of the Set Global Collision Off command I would write a function that will turn off collision for a range of objects, like:



Then just call that function right after all my objects are created, and afterward use the Set Object Collision On command to turn on collision for objects that I do want.

Login to post a reply

Server time is: 2025-05-25 06:24:46
Your offset time is: 2025-05-25 06:24:46