• ### What is your GameDev Story?

#### Archived

This topic is now archived and is closed to further replies.

# Newbie: How to detect polygon positions

This topic is 6541 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I''m a newbie, and I''ve started building my first 3D engine (see my web page). Currently I can still walk through walls. What is the best way to detect walls and block walking through them? I started out very basically by making a small world-editor that creates 3D cubes based on quads. The 3D engine allows you to walk through it. Best regards John Electron

##### Share on other sites
I''m sorry my web-page is still in Dutch. I really have to start working on an international page....

##### Share on other sites
That might not be as easy as you think, it involves collision detection and response, which is a very elaborate topic, you should check out www.flipcode.com where they have an excellent tutorial on collision detection, but if you really are a newbie, I would''nt recommend starting with something that hard...
I will however tell you that it is based on sphere-plane intersection routines, a lot of math is involved.
Of, om het in het nederlands te zeggen, collision detection is niet direkt iets gemakkelijk om zomaar mee te beginnen, maar als je het aandurft, veel succes

Een helpende Belg

##### Share on other sites
Ok, collision detection might be quite hard....
But I cannot imagine it would be too hard to detect me bumping into a wall?!?! I only want to stay inside the space I created.

greetings
JonhE

##### Share on other sites
What you need to do is cast a ray from your viewpoint along your velocity vector, then check if this ray intersects with any of the planes made up by the polygons in your world. Then, if you crossed a plane, you need to find the ray-plane intersection point and check wether or not this is locate within the polygon belonging to the plane. If this is so, you have collided with a poly in your world.
Now, how do you know a point is inside a polygon? Wel, you construct a plane for each side of your poly and the viewpoint, and then check wether the intersection point is on the inside of each of these planes.
BTW, if you are using triangles, there are other ways of checking if a point is inside a poly

Have fun m8

Edited by - Flous on February 19, 2001 7:49:10 AM

##### Share on other sites
If you are just trying to stay inside a square or rectangular space then it is easy. Let''s say x is your x-coordinate and z is your z-coordinate, and the size of the box is 10*10. Just say that if(x>5) z=5;
if(x<-5) z=-5;
if(z>5) z=5;
if(z>-5) z=-5;

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 28
• 16
• 10
• 10
• 11
• ### Forum Statistics

• Total Topics
634102
• Total Posts
3015534
×