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 / Please help me, I have a problem with Collision.

Author
Message
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 9th Nov 2004 06:23
Hello

I asked this very question weeks ago, but got no straight answer. I will explain what I am trying to accomplish, and then tell you the problem...

1) the red objects are the enemies, they are to run upwards.
2) the white boxes, are barriers, they are supposed to push the red enemies either left or right randomly.
3) the green objects are supposed to kill the red objects.
4) the blue objects are supposed to kill the red objects.
5) the brown object that the bullets are shooting towards, is also supposed to kill the red objects.

All of that works fine, but there is a problem with the Red objects, you see, sometimes two red objects hit the white objects, and are pushed into each other, they are colliding, and thus cancell any other collision out, so they are stuck together, and pass through everything. This shouldn't happen. I need to know how to keep the red objects from colliding with themselves. Any help would be appreciated, I will enclude the code now...



That is the whole program, run it to see what objects I am talking about (red, blue, green etc..) Well that is all for now. Please do not tell me to buy nuclear glory's collision DLL, as I am not inclined to spend any money

Thank you.

Guns arnt the problem, people are the problems, shoot all the people and guns arnt a problems anymore.
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 9th Nov 2004 13:43
MP,
I can see your problem, and it looks like a tough cookie to crack.

I'm just going over your code, and it would be easier if you comment it a bit more. Especially the area's to do with collision ( as this is where the problem is ) so that we can follow the flow of the code a little easier.

Jess.


Team EOD :: Programmer/All-Round Nice Guy
Aust. Convention!
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 10th Nov 2004 06:23 Edited at: 10th Nov 2004 06:36
Quote: " MP,
I can see your problem, and it looks like a tough cookie to crack.

I'm just going over your code, and it would be easier if you comment it a bit more. Especially the area's to do with collision ( as this is where the problem is ) so that we can follow the flow of the code a little easier.
"


Ok I added some comments to my code so that it's easier to find things...



Here is the collision code, seperated from the main code....



Guns arnt the problem, people are the problems, shoot all the people and guns arnt a problems anymore.
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 10th Nov 2004 14:01
MP,
Sweet, Now I can understand the flow of the code better, and I have spotted your problem.

When you are checking for collision, you are checking the "e" object ( in all your checks ) against, all other objects.
Now, as you said, when the two red objects collide, it effectively cancels out all other collision.

This is because when DBC does the collision checking, it first checks if object 'e' is colliding with object 1, then if object 'e' is colliding with object 2, and so-on untill there are no more objects to be checked, or if it finds a collision.

Now, since your red objects are between 6 and 15, and your white objects are between 203 and 207, it follows the collision checking routine as I said before, it'll check collision between 6 and 15 before it checks between 203 and 207. This means that if it finds a collision with one of the red objects, then it will return that number first, as it will come across that object that it is coliding with first.

Ok, so, you understand all that? I hope so.

To fix it, what you want to do, is do two For...Next loops, instead of one.

You want something like this;


Do you understand that one?
If you do, then I suggest that you change all of your collision code to something like this now, to avoid any future mess-ups with the collision.

If not, I can explain it a bit better, if you like?

Jess.


Team EOD :: Programmer/All-Round Nice Guy
Aust. Convention!
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 11th Nov 2004 03:53
I understand what your saying, but I am not exactly sure how to apply it. I did what you said, and my collision code for the enemies and barriers looks like this now....



But I am still getting collision problems, in fact alot of the time, the red objects just pass through the white ones.

Guns arnt the problem, people are the problems, shoot all the people and guns arnt a problems anymore.
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 11th Nov 2004 08:32
Alrighty,
First up, I made a mistake in the code I wrote, as I was writing it real fast last night.

It should be For i = 204 To 207, as the white objects go from 204 to 207, right?

Now, for the other collision problems, explain what's happening, and I should be able to see where it's going wrong

Jess.


Team EOD :: Programmer/All-Round Nice Guy
Aust. Convention!
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 12th Nov 2004 06:03
Ok, well I have a bit of a problem, now when two red objects move into each other, they don't cancell collision out, but rather just kill themselves. This should not happen, as both objects should remain seperate entities that keep moving up untill they come in contact with something that is supposed to kill them. So what should I do? I was thinking of making some kind of collision statement, that keeps two red objects from moving into each other, and thus keeping them seperate, but I am not sure how I would go about this. Any suggestians?

Oh and by the way, thanks for the help so far!

Guns arnt the problem, people are the problems, shoot all the people and guns arnt a problems anymore.
Louiz ofRohr
20
Years of Service
User Offline
Joined: 11th Nov 2004
Location:
Posted: 12th Nov 2004 07:02
A simple, light and beautiful collision math... Real collision with real limits... That isn't "if object collision(1,3)=1 THEN result"... Take a look at this simple box collision...
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 13th Nov 2004 11:39
Huh?? I Don't understand what you want me to look at.

Guns arnt the problem, people are the problems, shoot all the people and guns arnt a problems anymore.
Louiz ofRohr
20
Years of Service
User Offline
Joined: 11th Nov 2004
Location:
Posted: 16th Nov 2004 03:40
Sorry man, the code is here:


rem Texture for boxes (forget it)
ink RGB(0,0,0),0
box 0,0,100,100
ink RGB(150,150,150),0
y#=0 : x#=0
for l=1 to 20
line x#,y#,100,y#
y#=y#+5
next l
for l=1 to 20
line x#,0,x#,100
x#=x#+5
next l
get image 1, 0,0,100,100
ink RGB(0,100,0),0
box 0,0,100,100
ink RGB(0,120,0),0
for l=1 to 100
dot rnd(100),rnd(100)
next l
ink RGB(0,50,0),0
for l=1 to 100
dot rnd(90),rnd(90)
next l
get image 2, 0,0,100,100
cls

sync on : sync rate 60
fog on : fog distance 1000 : fog color 0
backdrop on : color backdrop 0
hide mouse

make matrix 1, 3000,3000,30,30
prepare matrix texture 1, 2, 1, 1

`o personagem
make object sphere 1, 50 : color object 1, RGB(200,0,0)
position object 1, 2500,20,2500

`the boxes of collision
for obj=2 to 11
make object box obj, rnd(50)+20, 50, rnd(50)+20
texture object obj, 1
ghost object on obj
position object obj, rnd(3000), 30, rnd(3000)
next obj

DO
if upkey()=1 then move object 1,5
if downkey()=1 then move object 1,-5
if leftkey()=1 then yrotate object 1,wrapvalue(object angle y(1)-5)
if rightkey()=1 then yrotate object 1,wrapvalue(object angle y(1)+5)

REM COLLiSiONS WiTH THE 10 BOXES AND THE STAGE LiMiTS
REM COLLiSiONS WiTH THE 10 BOXES AND THE STAGE LiMiTS
x#=object position x(1) : z#=object position z(1)
for parede=2 to 11
xe#=object size x(parede)/2 : ze#=object size z(parede)/2
xp#=object position x(parede) : zp#=object position z(parede)
`please, note that the "20" is a symbolic value for (object size 1)/2 and the "25" is a distance between the 2 limitations for complete 4sided collision
if ((x#>xp#-(xe#+20)) and (x#<xp#+(xe#+20)) and (z#>zp#)):
if z#<zp#+(ze#+20) THEN z#=zp#+(ze#+20)
endif
if ((x#>xp#-(xe#+20)) and (x#<xp#+(xe#+20)) and (z#<zp#)):
if z#>zp#-(ze#+20) THEN z#=zp#-(ze#+20)
endif
if ((z#>zp#-(ze#+20)) and (z#<zp#+(ze#+20)) and (x#>xp#)):
if x#<xp#+(xe#+25) THEN x#=xp#+(xe#+25)
endif
if ((z#>zp#-(ze#+20)) and (z#<zp#+(ze#+20)) and (x#<xp#)):
if x#>xp#-(xe#+25) THEN x#=xp#-(xe#+25)
endif
next parede
position object 1, x#,20,z#
REM XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
REM XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

xa#=object angle y(1)
set camera to follow x#,100,z#,xa#,100,100,3.2,1
xrotate camera 15
sync
LOOP

The worst foe lies within the self...

Login to post a reply

Server time is: 2025-05-24 19:03:49
Your offset time is: 2025-05-24 19:03:49