Minecraft Style Terrain Collision Detection and Ramps

Started by monsieurdozier, June 03, 2012, 23:35:43

Previous topic - Next topic

monsieurdozier

I've been racking my brain on how to get this to work.  Basically I'm working on a 3rd person game, with Minecraft-esque terrain.  I've created a Slope Block, which is basically a ramp.

I've worked out facing, drawing, etc. etc.  What I can't seem to figure out is how to make the character actually go up the freaking ramp.

Here's kind of what I have set up so far:
Player holds down the W Key.
The system goes through a check and finds which block is in the location of where the player is trying to move to.
The system checks to see if the moving point is in the Bounding Box of that point.  (To handle cases like blocks smaller than a full block size.  Think Minecraft fence posts).
If the point isn't in the Bounding Box, move to that point.

Then I come to the ramp.  I created a Bounding Slope subclass of my Bounding Box, and added a check to see if the point is also underneath a line connecting the lower front of the box, to the upper back of the box.  And I'm having all sorts of fantastic bugs with it.

My question is, am I on the right track, or should I just throw this mess away and try another tactic for terrain collision detection?  If you were to build a 3rd person game, with Minecraft terrain that includes ramps, how would you do it?

matheus23

I'm pretty sure Minecraft uses a Quake-like collision response system, which is quite easy: you find all the Triangles/Quads the player collides with/intersects, and then move the player along the average of all the normals, from the Quads/Triangles. That way it would also take more time to climb up a ledge, and it would be possible to climb up any ledge, if you are fast enough.
My github account and currently active project: https://github.com/matheus23/UniverseEngine

3DWalker

Minecraft uses box collision boundaries only if you look. and their collision and mainly for the objects on top, below, and on the 4 sides, check to see if the next point forward is inside that box, if so, don't allow movement along that axis.

With slopes it's be harder, you would just make the bounds out of boxes and make the boxes slowly increas in heigh, similar to how the stairs work.
The statement below is true.

The statement above is false.

dangerdoc

You could just use this process:

First you must know witch way is "up" on the slope.
Calculate how much percent you have gone horizontally along the axis that is up/down the slope (only focus on the way that is up, which may be the x axis).
For each slope, you have a value in the physics on "slope" where:
x = percent player has gone along slope
y = highest block height (percent of full block)
z = player height

z = x*(y/100)

Heres the logic:
if you assume that the low point of the block is 0, and you are given the high point and the distance from low point to high point, you can use (50 percent across block) to decide that it is 50% of the way from 0% high to 50% high.

If you have a low point that is different than 0, you can use this:

same values for x, y, and z
w = low point
#this is a comment#
z = x#percent across#*((y-w#distance from high and low#)/100#get 1 percent to multiply by x with#)+w#add low points height to result#

This is just like the first equation, except we have more input. In the first equation, we assume that the height is also the distance between the low and high points. Here we find the distance from low and high points, find 1% of that, and use x to find the height in relation to the low point. Finally, we just add the height of the low point to the height in relation to low point and we find the height in relation to the bottom of the block.

If you want speed change, you can just add a value in the blocks physics like "speed change". If the player is going down, you could change the speed to increase.

I hope this helps!
dangerdoc
“We build but to tear down. Most of our work and resource is squandered. Our onward march is marked by devastation. Everywhere there is an appalling loss of time, effort and life. A cheerless view, but true.” - Nikola Tesla