Skip to main content
GameDev.net gamedev.net
🔒 Locked

Problem with 3D edge collision

Started by MiltonPlotkin Dec 1, 2011 at 2:34 AM 7 replies 2k views
Original Post
MiltonPlotkin
MiltonPlotkin
Hello, first time posting, but here it is.

I have recently gone from programming in 2D Allegro to programming 3D DirectX. I have been trying to get a simple collision engine running for quite some time, my primary goal to make a sphere smoothly travel over angled terrain. So far, I have been mildly successful, and this works:
diagram.png

The ball successfully checks for the intersection of the planes normal from it's center, and slides down accordingly. No problem there.

However, I cannot get the ball to move accordingly when moving over the seam of two triangles, since it can no longer use the planes normal as calculation. I have tried this, but all it has accomplished is making the ball "spaz" whenever it gets near a seam and clip through:

diagram2.png

The above diagram depicts the ball outside of a triangles area (the triangle is facing directly towards the screen). A vector is made from each of the points of the triangle to the sphere (only one is shown), and projected on the corresponding edge. If the vector from the end of the edge projection to the sphere (blue vector) is smaller than the radius of the Sphere, move it by the amount of the intersection multiplied by the unit vector of blue.

I have managed to implement the above method in 2D, and it works fine, however, in 3D, the ball doesn't even need to be anywhere near the edge before it begins to "spaz" out. I'm wondering if it's a mathematical error rather than a coding one, would I be correct? Or is there an easier/different method I could use for this.

I understand this is asking for a lot. Thankyou very much for your help.
Krohm
Krohm
As far as I understand, Bullet requires the user to explicitly mark shared edges for improved processing. Odds are the solution might be more involved than I could possibly understand. Perhaps have a look at its code, they call them "internal edges".
Previously "Krohm"
MiltonPlotkin
MiltonPlotkin

As far as I understand, Bullet requires the user to explicitly mark shared edges for improved processing. Odds are the solution might be more involved than I could possibly understand. Perhaps have a look at its code, they call them "internal edges".


.........uh oh. I feel pretty awkward now... eh, heh, uh... am I on the wrong forum/thread? I'm not using bullet physics, I'm trying to make an engine from scratch.
Krohm
Krohm
Let me elaborate.
You want to do that yourself.
This is clear.
But I'm warning you: the people behind one of the major physics implementations around thinks the problem you're trying to solve is not trivial.
Therefore, I expect your simple solutions won't work OR won't scale.
I guess I should have been more explicit.
Previously "Krohm"
MiltonPlotkin
MiltonPlotkin
........well now I'm even more confused. I'm pretty sure what that comment meant was to discourage me.
dpadam450
dpadam450
When it moves over the seam I think you need to detect that it is sharing collision with both triangles and average them. Imagine a mountain peak. A ball hits the peak, it should bounce up (the average normal) and not left or right of the peak. Maybe that helps. I have not done much physics but that should be what you need.

This video shows that there is a case when an edge hits that I just found, so I assume the above I posted would work. Or send him a youtube message.
http://www.youtube.c...h?v=pEftJ1Rv9PE
NBA2K, Madden, Maneater, Killing Floor, Sims 
HappyCoder
HappyCoder
Do you ensure that the edge/sphere checks to see if the collision happens between the endpoints of the line? If not edges nowhere near the sphere may be colliding with it because it is actually a line going infinitely in both directions. You also would need to check the corners of the triangle against the sphere as well, but you can handle that when you come to it.
My current game project Platform RPG
MiltonPlotkin
MiltonPlotkin
Hm...

Thanks everybody for the help. I'll write back when/if I figure out what I'm doing wrong.

EDIT: You were right. I do have to average the two triangles lines. Thanks!!!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.