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 Professional Discussion / Collision detection help

Author
Message
wattywatts
17
Years of Service
User Offline
Joined: 25th May 2009
Location: Michigan
Posted: 23rd Dec 2010 07:02
Hello everyone,
I'm working on a top down view game, and I'm having serious problems with the collision detection.
I hate messing with it so much that I exported each object from 3d world studio separately and loaded them separately in dbpro, so that I could use automatic object collision. However, I'm having some problems with that, too.
I'm used to doing similar stuff in a first person game, but with a character on screen it's different. I set up variables for the position of the character, and then made the camera also move dependent on those variables. But when the character hits a wall, he stops but the camera keeps going. It's very frustrating, and I seem to have fixed it for the most part, but now the collision detection is very jerky.
If anyone could help me clean up this code I'd really appreciate it!
wattywatts
17
Years of Service
User Offline
Joined: 25th May 2009
Location: Michigan
Posted: 27th Dec 2010 08:06
Bump... (please?)
BillR
23
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 27th Dec 2010 14:27 Edited at: 27th Dec 2010 16:10
Im working on your code, but first off you can't say
if upkey() = 1 and leftkey() = 1 and object collision(25, 0)>0 = 1 then c=c-2 : a=a-1
">0 = 1" doesn't work right, you can't really say that
either leave off the =1 (collision(25, 0)>0 is sufficient)
or use parenthesis to group logical checking

also saying "then :" isn't a good practice, remove the ":"
back in a while...
BillR
23
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 27th Dec 2010 15:04 Edited at: 27th Dec 2010 15:14
Okay, so I separated your code logic as best I could

What are your variables a and c used for?

The problem arises when 2 keys are pressed, such as left and down
1) first the left=1 logic is executed,
2) then the down=1 and left=1 logic is executed
making some logic run twice basically

I would suggest getting all the left and right code out of the up and down code areas,
treat each key separately.
Give that a try.
wattywatts
17
Years of Service
User Offline
Joined: 25th May 2009
Location: Michigan
Posted: 28th Dec 2010 07:43
Thank you SO much BillR, it's much less muddy now.
a b and c are just in place of the x y and z of the character and camera positions.
I'm getting a weird bug where the left key + collision will force the character past objects instead of blocking him, and I'm off to decipher your code.
Thanks again.

Login to post a reply

Server time is: 2026-07-21 20:35:22
Your offset time is: 2026-07-21 20:35:22