Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (481)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (548)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Voxel Engine Collision Response  (Read 425 times)
0 Members and 1 Guest are viewing this topic.
Offline lolzballs

Junior Newbie


Exp: 2 years



« Posted 2014-03-04 01:39:01 »

I just wanted to start off by saying that I'm pretty sure there is something out there on this topic, but I don't really understand them. Please don't scream at me to Google it.

So, anyways, ahead with the question. I've started working on a Voxel game(just a Minecraft clone to work on programming), and I've got some rendering done. This rendering isn't very complicated, but I want collision done before the other stuff. I've gotten AABB's setup and collision detection down, but I couldn't get the collision detection working. Also, this collision doesn't work if the player is travelling extraordinarily fast, so I was also wondering if there was a better method.

I'm using this to determine collision:
1  
2  
3  
4  
5  
6  
7  
8  
if (boundingBox.maxX + boundingBox.x > aabb.minX + aabb.x &&
                    boundingBox.minX + boundingBox.x < aabb.maxX + aabb.x &&
                    boundingBox.maxY + boundingBox.y > aabb.minY + aabb.y &&
                    boundingBox.minY + boundingBox.y < aabb.maxY + aabb.y &&
                    boundingBox.maxZ + boundingBox.z > aabb.minZ + aabb.z &&
                    boundingBox.minZ + boundingBox.z < aabb.maxZ + aabb.z) {
                return true;
 }

boundingBox is the player AABB and aabb is the AABB that we are checking collision for.
I'm adding the maxX to the x position, because the maxX is not absolute.
Offline The Lion King
« Reply #1 - Posted 2014-03-04 01:59:48 »

The problem you are describing is referred to as tunneling. call your delta movements for the next frame as dx, dy, dz. After you check your collisions in one frame and if you know the object is moving really fast then do this if statement.


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
boolean collisionNextFrame = true;

if(dx > 0)
{
      if(boundingBox.maxX + boundingBox.x + dx < aabb.minX + aabb.x ||
                    boundingBox.minX + boundingBox.x > aabb.maxX + aabb.x)
       {
               collisionNextFrame = false;
       }
}
else if(dx < 0)
{
           if(boundingBox.maxX + boundingBox.x < aabb.minX + aabb.x ||
                    boundingBox.minX + boundingBox.x + dx> aabb.maxX + aabb.x)
       {
               collisionNextFrame = false;
       }
}

//same thing for y and z
//if collisionNextFrame is still true then it will collide


"You have to want it more than you want to breath, then you will be successful"
Offline lolzballs

Junior Newbie


Exp: 2 years



« Reply #2 - Posted 2014-03-07 02:10:42 »

Thanks but I really need the collision response. Thanks though!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline trollwarrior1
« Reply #3 - Posted 2014-03-07 06:49:33 »

i'm pretty sure minecraft doesn't use collision like this.
minecraft probably stores tiles as arrays which you can access.
when you want to check for collision, you add speed values to moving object's coordinates and divide them by tile/cube size. now you got tile's/cubes' coordinates on which the object will be once once you move it. all that is left to do is to get the tile/cube with coordinates you calculated and check if you can move in that tile/cube.
Pages: [1]
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

atombrot (27 views)
2014-08-19 09:29:53

Tekkerue (25 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (15 views)
2014-08-16 06:20:21

Tekkerue (22 views)
2014-08-16 06:12:11

Rayexar (61 views)
2014-08-11 02:49:23

BurntPizza (39 views)
2014-08-09 21:09:32

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38

BurntPizza (67 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!