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 / Math cube collisions

Author
Message
Hell IVIonkey
23
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 1st Apr 2003 10:44
Perhaps this is a bit of an advanced question for those of you who use OBJECT COLLISION(), but perhaps not.

I'm writing a cube-based game (think tile-based in 3d). I need to clip the player against each cube. I do not want to use the built-in collision system, for it's slow. I don't want to use x# = oldx# type resolutions because they're jumpy and not all that accurate. Instead, I'm using math collisions.

Here's the concept I have so far, psuedo-psuedo-code style:

Similar tests apply to the remaining 4 sides.

However, when I run the game, colliding with a cube causes the player to jump to unwanted positions. When I restrict the collisions to X and Y (no Z), it works fine. Once I have all 3 implemented, it goes foobar.

I'd post my code, but it's really confusing out of context, and is really difficult to explain the context. Does anybody know how to proberly implement a math 90-degree cube-on-cube collision system?

Thanks
Hell IVIonkey
23
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 1st Apr 2003 10:53 Edited at: 1st Apr 2003 11:00
Oh, what the hell... here's my code snippet.



I know it's a lot of code and a lot of repetition. Two reasons: line length limit, no short circuit evaluation in DB (like in C/C++) ...(or is there? I can't get it to work).
Also, the line:
if board(zfront, xmid, ydown )>=1 and board(zfront, xmid, ydown)<=65
A value between 1 and 65 in the board() matrix is a solid cube.



The function I called is here. It basically returns a 1 if the requested variable is a valid entry in the game array.
Hell IVIonkey
23
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 2nd Apr 2003 01:37
Looks like this was too confusing...

Ok consider a 2d collision with a player and 2 objects. How do you resolve an issue like this? How do you expand the issue to 3d? Remember, I'm not using oldx#, oldy#, or oldz# to reassign to x#, y#, or z#. But I'm sure I could create a velocity vector using the old and new variables. Perhaps this would be helpful in some way.
TRS80Model1
23
Years of Service
User Offline
Joined: 2nd Feb 2003
Location: - Please Select -
Posted: 2nd Apr 2003 02:57
That doesn't help me much, where are you checking, (left,right) and (back,front), I've done this for my second mario game, 3d tile collision(just expanded the original collision to back,front, but we need to know more details to help.
Hell IVIonkey
23
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 2nd Apr 2003 03:11
I need to check for collisions on all 6 sides. This is just a diagram of a problem I've encountered, reduced to 2d.

I suppose what I've done in the code above is test each vertex of the bounding box to see if it's overlapping any nearby level cubes. If it is, I'm trying to set only either the x, y, or z so that the offending vertex will be exactly aligned with the edge of the level cube. Problem is, which level cube do I try to align the offending vertices with and which face of the cube (left vs right, top vs bottom, front vs back) do I align them with.

How did you do your collision tests? (Assumedly so that you didn't use OBJECT COLLISION() or any setting of x, y, or z with oldx, oldy, or oldz.)

(Also, is it easier to think of the objects as having plain collide with plain, plain with vertices, vice-versa, or vertices with vertices?)
TRS80Model1
23
Years of Service
User Offline
Joined: 2nd Feb 2003
Location: - Please Select -
Posted: 2nd Apr 2003 03:39
The fastest way I've come up with for tile based 2d or 3d is are arrays and math.(being that all your tiles are the same size), otherwise you have to make a collision algorithm for each different tile. (then for precision collision, like body parts, I used a pixel counter with some math.)
Hell IVIonkey
23
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 2nd Apr 2003 03:51
That's exactly what I'm doing. It's a 3d matrix (as I showed in my source code). Problem is that it doesn't work... for the reasons that I've demonstrated above. How do you determine where to place the player after a collision?
TRS80Model1
23
Years of Service
User Offline
Joined: 2nd Feb 2003
Location: - Please Select -
Posted: 2nd Apr 2003 05:58
After a collision I just leave the player where he is, unless something else is supposed to happen. Like for gravity, you check his feet, or forward, backwards, up, down, diagnal, all directions. It would help if you could say what your player is supposed to do after a collision, every game is different.
TRS80Model1
23
Years of Service
User Offline
Joined: 2nd Feb 2003
Location: - Please Select -
Posted: 2nd Apr 2003 06:05
Your way of math collision is way different than I would do it, um, why do you have floats in your collision code? You can't get half a pixel.
Hell IVIonkey
23
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 2nd Apr 2003 06:13 Edited at: 2nd Apr 2003 06:30
The player should be aligned so that his right edge (for example) is in the exact spot as the left edge of the block. Same applies for any direction. I suppose it's like sliding collision, but not as complex, since all angles are 90-degrees (recall that sin90=1, etc...). A Y-col will not affect the Z and X coords. Same idea goes for an X-col and a Z-col.

It sounds like you've just stopped the player from moving. Or perhaps restricted his movements to only the remaining available x-y-z directions. I need to do this PLUS make the player exactly touching the object he just ran into, not .005 units away or something (as oldx, oldy, oldz implementations do).

Maybe it sounds like I'm being picky, but I need to be very precise with this particular game.
Hell IVIonkey
23
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 2nd Apr 2003 06:19 Edited at: 2nd Apr 2003 06:40
Quote: "Your way of math collision is way different than I would do it, um, why do you have floats in your collision code? You can't get half a pixel."


Perhaps. However, it's needed. As an example, consider a ball of radius .5 positioned at the origin. Every 5 units, there is a brick space (on or off). Each brick space is determined by a matrix. Want to know when the ball hits the brick? Plug in the ball's X into the matrix like so: xtest=int(x#/5); from here you can call matrix(xtest) to find if that cell is filled or not. Need to know the right bound of the ball? Change the formula to xtest=int(x#/5+.5). That's why.

It's basically a way of telling how to round a float. IE: rounding value=17.67 can be done by int(value+.5)

Hmm, I'm not doing a pixel based game anyhow. Here's a spoiler screenshot:
TRS80Model1
23
Years of Service
User Offline
Joined: 2nd Feb 2003
Location: - Please Select -
Posted: 2nd Apr 2003 06:41
Ok, here is my simple collison routine for my 2d game I was going to enter into the retro compo, but not now, cause of no free time. Some of it is still debug. This checks a 2d array for tiles and I work off of them. In 3d you need a 3d array to do this Plus more checks. When your objects move in space, do they remain the same size? Like player? Is your background moving under your player, or is your player moving into the background and back?
TRS80Model1
23
Years of Service
User Offline
Joined: 2nd Feb 2003
Location: - Please Select -
Posted: 2nd Apr 2003 06:48
After looking at that picture, I don't think I was thinking right, but I know that if you keep track of the sizes of your objects in another array and use a 3d array math routine you can get quick precise (Flat Surface) collision without all the float slowdown.
TRS80Model1
23
Years of Service
User Offline
Joined: 2nd Feb 2003
Location: - Please Select -
Posted: 2nd Apr 2003 06:53
I think I see a problem, you are mixing integers with floats. That doesnot give correct results in darkbasic.
Hell IVIonkey
23
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 2nd Apr 2003 07:06
All the blocks are the same size of 20x10x40 (x,y,z). I can make exceptions for the tunnel pieces. However, the player is 7x4x8 (as a rough estimate that will most likely work). He's centered about x and z, but his y coord describes the very bottom of him (same coord as the top of the floor below) - this could be changed if necessary. I'm currently using 3d array routines, but they don't work correctly. How can I implement this flat surface collision? (And what float slowdown are you referring to?)
Hell IVIonkey
23
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 2nd Apr 2003 07:09
Quote: "I think I see a problem, you are mixing integers with floats. That doesnot give correct results in darkbasic."


The hasn't been a problem in this particular case yet. When I used my current method and removed z-collisions, it worked perfectly. I have the game print up the coords of the bounding box in real time, and they look perfect for plugging into a matrix function. Problem is, the function is wrong, for if you use it with all 6 directions, the collisions make the player shoot all around the screen.
TRS80Model1
23
Years of Service
User Offline
Joined: 2nd Feb 2003
Location: - Please Select -
Posted: 3rd Apr 2003 01:44
If you send me the project I may be able to fix it for you, I'm new with Darkbasic but am a veteran of 20 yrs with c,c++, and assembly. Don't worry I'm not out for a name, Darkbasic is just a new hobbie for me.

icq=22910209 or [email protected]
Hell IVIonkey
23
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 3rd Apr 2003 12:26 Edited at: 3rd Apr 2003 12:48
Hey, thanks for the help so far. I think I finally made some progress though. In the example code I gave you, first you may want to set the camera to a top-down view to see this better. Then replace the sub "collisions" with this.

Right now, it only tests for collisions from the right and the left, but checks every relevant vertex of the bounding box against the block. There may be room for optimization here, but I think it's a much better start. The question now is "Will it hold up when the tests are expanded to 3d?"
Pricey
23
Years of Service
User Offline
Joined: 22nd Feb 2003
Location:
Posted: 11th Apr 2003 17:00
that GRAV-O-METER and JUMP-O-MASTER look VERY similar to that old DOS game: SKY-ROADS!

[age 11]

Hell IVIonkey
23
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 11th Apr 2003 19:25
Bingo!

I was going to enter it into the Retro Compo, but ran out of time. Anyhow, it's a fangame of SkyRoads. I actually had a talk with the original programmers just for fun!

Login to post a reply

Server time is: 2026-06-11 17:31:17
Your offset time is: 2026-06-11 17:31:17