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 / Collision Problems :(

Author
Message
Still Remains
14
Years of Service
User Offline
Joined: 18th Jun 2009
Location:
Posted: 22nd Jun 2009 09:43
Alright so I'm having some problems figuring out collisions. I've read through TDK's tutorial covering it a few times and I can't seem to figure out what I did wrong. It's fine as long as I don't back up into the other object and it kind of bugs out a little bit if I rotate and move by the object.

If anyone could offer some advise it'd be much appreciated. Thanks
Still.Remains

Robert The Robot
17
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 22nd Jun 2009 22:09
Hi Still Remains, welcome to the forums!

Your code looks in pretty good shape, just one or two minor goofs. To answer your questions:

1)when you move cube 1 forwards and it bumps into the "wall", you told cube 1 to move backwards until it was no longer colliding. Now, if you are moving backwards and then you bump into the wall, you still move backwards until no collision occurs. Result? The cube moves straight through the wall!

2) You also mentioned a problem with the cube 'sinking into the wall' when you rotate it. I could be mistaken, but I believe your collision box does not rotate with the box (in other words, DB is checking for a collision between the cube and the wall as if neither had been rotated).

So, here's your code back with a few modifications to solve the problems:


For Problem 2, I've just enlarged the collision box. Somewhere between 35 and 40 seems ideal, I just haven't been able to fine tune it any better (I tried adjusting the flag at the end from 0 to 1, but it disabled collision entirely).

Problem 1 needs a more in-depth look. There's probably a better way of doing this, but after moving your object you store the position. If a collision occurs, you call "get object collision x()" for X, Y and Z. The help files say this returns sliding data - I think it actually tells you how far into the wall your cube has been pushed in. For example, if half the cube is inside the wall then these commands will tell you what you must do to the X, Y and Z coordinates of the object in order to move it back outside the wall. So, we decrease the position of the opbject by the specified amount, reposition the object, and on screen it looks as though the cube never enters the wall - the wall has become a solid object!

Hope this helps!

"I wish I was a spaceman, the fastest guy alive. I'd fly you round the universe, in Fireball XL5..."
Still Remains
14
Years of Service
User Offline
Joined: 18th Jun 2009
Location:
Posted: 23rd Jun 2009 00:13
Alright, thank you yea that did help out alot
Robert The Robot
17
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 23rd Jun 2009 11:49
Your welcome

Actually, you might want to take a look at the Basic3d example "exam25.dba", it's where I found all the sliding collision code (I've never understood any of it myself)

"I wish I was a spaceman, the fastest guy alive. I'd fly you round the universe, in Fireball XL5..."

Login to post a reply

Server time is: 2024-05-20 10:13:24
Your offset time is: 2024-05-20 10:13:24