Slopes just plain confuse me...

Started by
13 comments, last by BrianDra2 23 years, 4 months ago
Okay, here we go! I`ve created a simple 3D landscape that I would like my character(not a vechicle, but a living, breathing polygonal thing)to walk across. The problem is, the landscape isn''t just flat, there''s hills! But my character just walks right through the hills as if they''re not even there! So my main question is how do I get my character to climb up(and down) the hills. Now onto the fun stuff... I`ve got access to all the faces in the landscape, and all the vertices the faces are made up of. I`ve also got access to the normals of the vertices. (I`m using direct3d retained mode, if anybody cares) I`ve got access to the position of the character, and which face he''s standing on. So with that information, what can I do to tell my character to move up or down the hill? Are there any tutorials, websites, books, or anything at all that will help me understand how to do this? I know I probably have to use the slope formula, but I don''t see what to do once I have the results of the formula. Thanks, Brian Draeger briandra2@aol.com
Advertisement
You really don''t need a slope formula per se. Just take the desired velocity vector of your character, and when it intersects a polygon, adjust it''s real velocity to become the projection of the original vector onto the plane formed by the polygon (which should be trivial as you have the normal of the polygon.
Here''s one way of doing the sums;

take 1 vertex of the face
get a distance between that vertex and the player (xdis & zdist)
player height = vertex.y + (xdist * xnormal) + (zdist * znormal)

Something like that anyway

Cheers

Matt



Thanks for the answers:
SiCrane - Your answer is beyond my intelligence. Maybe if I take some more math courses I`ll understand what your trying to say. Thanks anyway.

3DModelMan - I tired out your formula and it works! My little character now happily climbs up a hill with ease. However, when the character trys to climb down a hill, he falls about 5 feet and then continues to climb downwards. This is probably a problem in my code, but if you have any ideas please tell me.

Thanks,
Brian Draeger
briandra2@aol.com
3DModelMan - I''m really dumb with maths - why do your equations work - I never thought it would be that easy?
Chris
Thanks for asking Chris, the truth is IT DOESN''T WORK!! Your question made me go back to write an explanation!

My terrain code was the first thing I tackled for my project and I was still experimenting A LOT. For a start I was normalising the surface normals incorrectly. Something I realised a long time ago, but never went back to fix it, if I had I would have found this problem sooner.

I was dividing by the larget component, to make one of the values 1.0 and the rest a product of it;

(12, 18, 7) became (0.6666, 1, 0.38888) - divide by 18

My solution currently *approximates* the result at best. I never really noticed much error because my ground faces are quite small, so I think this is why it still looked ok even on 45 degree faces.

Sorry if I''ve led anyone astray.

I''m about to start a complete bounding box collision detection system for my vehicle so I''ll need to fix it!

Bye

Matt



Oh well - when you do get it running - let us know!
Thanks
Chris
I don''t use D3D... but I''m having the same problem with my app. What is "xnormal" and "znormal"?

Anonymous Poster:
xnormal and znormal are the normals of a face - assumably the face your character is standing on. Most SDK''s have functions that will find the normal of a face. I don''t know how to find a normal of a face otherwise..
I''m having the same problem.. it really astonishes me that there is no "tried and true" formula for doing this. It seems like everyone and their dog would be making a simple terrain for someone to walk over.

I can get the normals for a face from a built in function based on three coordinates. But to be honest I have no idea what the heck they mean. I know a normal runs perpendicular to my face... but what do the xyz of that vector point to? A point in space? From my experiments they seem to point the opposite way and barely move no matter what direction the face is pointing.

Sigh. I''ll never figure this out.

This topic is closed to new replies.

Advertisement