Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


How to get sliding response to collisions (voxel terrain, mini-voxel camera)


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Mythix   Members   -  Reputation: 122

Like
0Likes
Like

Posted 04 June 2013 - 10:22 AM

My collision detection seems to work well. Responding to it, however, does not. My terrain is made of cubes. My player is made of a cube. They are all axis aligned. As my terrain is divided up into cubes, I simply check to see if every corner of the player's cube is in empty space or a solid block. If even one is in a solid block, then I know a collision has occurred.

I'm wanting to slide the player along the plane of the collision, but I'm having some difficulty understanding how to identify the plane to slide on and how. Everything I've tried so far seems to have issues determining the exact plane to slide on/propel from.

As the picture below demonstrates, from one frame to the next, if the red square moved from bottom up as the arrow points, I need something to show that the bottom face of the black square is what was collided with (or the top face of the red square).

 

phOST.png


Edited by Mythix, 04 June 2013 - 11:21 AM.


Sponsor:

#2 grhodes_at_work   Moderators   -  Reputation: 1361

Like
0Likes
Like

Posted 04 June 2013 - 12:40 PM

Are the cubes all the same size (as in, say, a voxel representation)? Let's say your player cubes are larger than some of your terrain cubes. Then, your test that only checks the containment of the corners will be insufficient. The player cube could entirely surround a terrain cube such that no corner is inside a terrain cube but the cubes would still volumetrically overlap. For example, see below....the player cube corners denoted by 'p', and terrain by 't':

 

                                      p---------------------------------------p

                                      |                                                |

                                      |              t--------------t               |

                                      |              |                 |               |

                                      p-----------|--------------|------------p

                                                     |                 |

                                  t---------------t--------------t---------------t

                                  |                  |                 |                  |
                                  |                  |                 |                  |

                                  t---------------t--------------t---------------t

 

One approach to deciding which plane to slide against would be to consider the outward-facing surface normal of all the faces of the colliding cubes. The collision/contact plane will be a plane between two cube faces whose normals point in opposite directions. The bottom plane of the black cube points down and the top plane of the red cube points up....opposite directions, so the bottom plane of the black cube would be your collision/contact plane.

 

grhodes_at_work


Graham Rhodes Moderator, Math & Physics forum @ gamedev.net

#3 JohnnyCode   Members   -  Reputation: 311

Like
0Likes
Like

Posted 04 June 2013 - 08:57 PM

My terrain is made of cubes. My player is made of a cube. They are all axis aligned. As my terrain is divided up into cubes, I simply check to see if every corner of the player's cube is in empty space or a solid block. If even one is in a solid block, then I know a collision has occurred. I'm wanting to slide the player along the plane of the collision

 

If we are at the voxel defined physics, this physics has an extreme advantage over subject physics. First let see what the cubes should do when they collide. A fundament of physics, in general is, that a subject has a tendence=speed vector by which it travels (or would travel) if no forces are being applyed on it. What is a force and why it start to apply later. In our case of the two cubes, lets consider that there are no attraction forces and the two cubes move their tendence as shown in the picture. If you know where they have the mass center located (innertia vector), you can tell perfectly what they will do now. Consider innertia tensor at the center of cube, for both of them.In your example you have a perpendicular angle, but one of the corners of the two cubes will be the first to call force. cubes are close and a force is created on the detecting corner, a point in space. After this,  innertia of cubeA , innertia of cubeB and the point of collision forms two vectors, which are know all suficient for direction of incoming tendence on the cubes individualy. But the size of tendence donation is unknown. Size of tendence donation is computed from weight of the donating object. It seems strange, but it is so, that speed doesnt matter and that the objects dont know eachother mass. But in virtual world you know their mass'. If the cube A is 1000 times havier than cube B. cube.A will add to its tendence 1/1000 of cube B tendence and cube B will add to its tendence 1000 of cube A tendence. After this, they move by their new tendence until collision point happens again.  the corners are sufficient information to produce exact connection point, which of course does not have to be on a corner. In our case, very soon another connection point may be triggered, but the innertia tensors got moved a bit by new tendence in time, and the slightly different directions compute this time, which results in sliding effect in time.



#4 radioteeth   Prime Members   -  Reputation: 1146

Like
0Likes
Like

Posted 05 June 2013 - 09:06 AM

Once you detect intersection, you must find the surface normal of the voxel.. This can easily be done on-the-fly using gradient analysis by averaging the positions of all empty voxels surrounding the intersected voxel (edit: in a 3x3x3 area, relative to the intersected voxel), normalize that vector, and 'push' the intersecting object back out along that calculated surface-normal so that the intersecting object is 'corrected' to the surface - yielding a 'sliding' effect when the object collides with the voxel volume.

 

you might want to also create an elastic effect (for certain entities) which simply 'reflects' the object's velocity by the surface normal, perhaps simply have an 'elasticity' entity property value, which determines the ratio of slide-to-bounce.

 

the velocity of the colliding object will also need to be corrected, in a similar fashion.


Edited by radioteeth, 05 June 2013 - 09:07 AM.


#5 radioteeth   Prime Members   -  Reputation: 1146

Like
0Likes
Like

Posted 05 June 2013 - 09:09 AM

oh, and this would be for fine-grained voxel simulations. If you are simply using cubes to represent your world, then you simply need to find what side of the voxel the object is intersecting, and push out along one of the six cube-normals.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS