Advertisement

Detecting holes

Started by November 29, 2001 06:32 AM
5 comments, last by Muksitul 23 years, 2 months ago
HI Iv been working with collision detection to detect walls SO far i have done with is sphere binding which seems pretty good to me. But i am having a problem, when there is a hole in the ground how do i detect it ? btw Im using lesson 10 of NeHe, so im using textured triangles. If anyone can gimme a clue please help. THank you Terrorisk
Perhaps ray intersection. Cast a ray downward, if it intersects floor there is no hole, if it does not, there is. Mind you, I do not know the technical meathod for doing this. It may not even work, just an idea that someone else will say "THAT WILL WORK!" or "NO! YOU IDIOT!" to. Good luck.

Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
"Please help, I''m using Windows!"
Alex BroadwinA-Tronic Software & Design-----"if you fail in life, you were destined to fail. If you suceed in life, call me.""The answer is out there.""Please help, I'm using Windows!"
Advertisement
Ok
here is my data
My sphere binding is doing col det only against x and z axis
by g_zpos and g_xpos


// HOLLOW GROUND
3
15.0 -1.0 0.0 1.0 1.0
15.0 -1.0 5.0 1.0 0.0
10.0 -1.0 5.0 0.0 0.0
3
15.0 -1.0 0.0 1.0 1.0
10.0 -1.0 0.0 0.0 1.0
10.0 -1.0 5.0 0.0 0.0

bool Collision(int normal, int dir, float bounding)
{
float dest, facex1, facez1, facex2, facez2 , facey1, facey2; // face coordinates
int facenorm; // The normal of the face being tested
bool result=false; // The result of the function (true=collision)
for (int i=0; i {
// Face coordinate definition

facex1=g_sector1.triangle[i*2].vertex[0].x; // 1st X Vertex
facex2=g_sector1.triangle[i*2].vertex[2].x; // 2nd X Vertex
facey1=g_sector1.triangle[i*2].vertex[0].y; // 1st Y Vertex
facey2=g_sector1.triangle[i*2].vertex[2].y; // 2nd Y Vertex
facez1=g_sector1.triangle[i*2].vertex[0].z; // 1st Z Vertex
facez2=g_sector1.triangle[i*2].vertex[2].z; // 2nd Z Vertex
//Determine Face Normal
if (facex1==facex2 && facez1 != facez2) // If X Coordinates are equal and Z aren''t
facenorm=0; // The normal is X
if (facex1!=facex2 && facez1 == facez2) // If Z Coordinates are equal and X aren''t
facenorm=2; // The Normal is Z
if (facex1!=facex2 && facez1 != facez2)
facenorm=1; // The normal is Y

can i make use of this normal Y to detect holes
Because I wrote the above code I think I might be able to answer your question. In the collision function you notice there are tests for planes with Z-normals and X-normals, just add a test for planes with Y-normals and then insert this in DrawGLScene:

if (!Collision(1, 0, 0.35(or whatever the radius of your sphere))
{DropPlayer();}

Remember to assume in the collision function that the dir parameter doesn''t matter because you drop no matter what.

I hope this helps, even though it probably won''t.



This has been a post by oglman, King of all that is holy.
Hmm
since I can only detect walls by checking the z and x-axis
and I cant check Y axis.
BEcause in the code all the walls or holes are being chcked at every location
How am i suppose to know when it goes near the hole ?

Why not make a map of all the ''holes'' in your level and test against that?

Or cover the holes with an invisible surface (one that doesn''t get drawn) and test against that?

Just some ideas anyway.



-----------------------
glDisable(WORK);
glEnable(GL_CODING);
-----------------------Current Project: The Chromatic Game Engine
Advertisement
Wouldn''t it work fine with just a simple line/plane intersection test downwards? ...I belive that was what i did when trying something close to what you are doing...

Take Care!

- -- ---[XaOs]--- -- -

[ project fy ]
- -- ---[XaOs]--- -- -[ Project fy ||| CyberTux ]

This topic is closed to new replies.

Advertisement