Archived

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

Movement on a 3D surface

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I posted this in the beginners section because I considered myself a beginner, but have gotten no answer....so here''s my rant/question.... Ok, so I''ve kinda gotten into the 3D game programming a little late (2nd year of college). It''s always hard trying to figure out what you need to know in order to do what you want (and also having the funds to do so). I really love it. A couple friends and I have decided to make a game before next years game developer''s conference (or at least a demo). Nothing too fancy, but something to show off to try and sack a coop in the business. At the moment, I''m having trouble figuring out how to calculate a character''s movement along a surface of polygons. The problem I have is that I can''t figure out how to get the character to move across multiple polygons without keeping track of all the vertices. What I was doing was treating the character as a point on the surface...and it''s easy doing just one surface, but the problem is doing many connected surfaces. Any suggestions? Any better way of doing it? Any other help would be great also.

Share this post


Link to post
Share on other sites
Well, the way most games do it is you perform a simple check each frame to determine if you are on ground or not on ground by trying to trace a single unit into the ground. If you are not standing anything, then you apply gravity and have the object fall. Otherwise you trace in the movement direction and move the object (and subsequently next frame the object will check to see if it is on the ground or not).

Share this post


Link to post
Share on other sites
That requires keeping track of all vertices, but is there a way to do it without keeping track of all the vertices all at once....like maybe store a linked list in a vertices that points to all vertices it is connected with?

[edited by - Dendei on February 20, 2004 1:54:56 PM]

Share this post


Link to post
Share on other sites
Well, shit....I think I just figured out how to solve my problem....I''m a moron. I didn''t think about my data structures class when they taught us graphs. That was stupid of me....

Share this post


Link to post
Share on other sites
You need to test all of the verts that you might come in contact with. You cannot know anything about the world around you unless you perform tests, subsequently you cannot know what polygon you are over unless you perform mathematical tests. If you want to do what I think you want to do, which is automatically know what polygon you are on, you would have to first test all of the polygons at startup to know what polygon you are originally on, and then when you move from one polygon to a neighboring polygon, you would again have to perform mathematical tests to see which neighbor you are on. In short, you cannot ever know anything without performing tests.

In reality, computer game worlds are partitioned into pieces, and you typically have a start point and an endpoint, you find which 'pieces' of the world you cross over to get from the start point to the end point, and each of these pieces of the world has a bunch of polygons or other collision detection structures that you must test for collision.

[edited by - Shadow12345 on February 20, 2004 2:32:52 PM]

Share this post


Link to post
Share on other sites
Ok, what I said before you posted was that if I have each vertex keep track of all the other vertices that are connected to it, it will cut down on the amount of testing that needs to be done. Basically, I move towards the edge of a polygon and am about to cross over the line that connects the two points. At this point, I will take the two vertices that make this line and compare their graph data to decide which vertex I will now be taking into account instead of the third vertex of the polygon that I am moving out of. This vertex data could look something like this:

struct vertex
{
int x = 0, y = 0, z = 0;
vertex *linksTo;
}

Share this post


Link to post
Share on other sites
I guess that would work okay. I just don't know how it will perform on sloping inclines, but you might not even want that. You will also need to handle when you cross over multiple triangles, but that shouldn't be too hard to implement. There are better methods of doing collision detection but what you suggest seems like it will work okay, so good luck.

EDIT:
I would change your data structure from vertex to triangle. This will be easier because if you have a triangle, you know that there will always be exactly 3 neighbors, and then each triangle has its own verts.

[edited by - Shadow12345 on February 20, 2004 2:49:54 PM]

Share this post


Link to post
Share on other sites
well, if the angle between the two triangles is less than is what you want to allow, then don''t let them walk any farther. Hmm, the only problem there is if it just keeps curving within the specified limits. Well, I''m pretty sure some of our characters are going to be able to walk on walls and ceilings. What I could do is every time I start to walk up something keep track of the overall angle by adding all the smaller angles between two triangles together. Once the overall angle reaches your stopping angle, then the person will stop.

Share this post


Link to post
Share on other sites
You''re making this too complicated. Start with a flat surface, see if you can even get that working, and I wouldn''t even think about dealing with inclines until you have something robust with the flat surface.

Share this post


Link to post
Share on other sites
You could maybe cast a ray from the character''s location straight down, then check for the point of intersection between that ray and the polys of that surface. By using the point of intersection, you can get the distance from there to the starting point of the ray. Or something like that. I think I just said it all backwards though.

Share this post


Link to post
Share on other sites
The only thing I was saying with your method is that it was not answering my question (either because I asked wrong question or you misunderstood it, but neither are important at the moment). I wanted a way to cross between triangles without having to run a test to see what the new polygon is that you just entered without having to scan through all the triangles that make up the map. Now, what I was suggesting is that you don''t even need to run all these tests if you keep the vertices in a Graph such as described in my CS class that I did not take into consideration at the time of my original post. This limits the number of vertices that you have to scan in order to determine the new triangle that you are on top of. Ok, the way you were suggesting was taking into consideration that either you already know what triangle you are on, or you would have to scan the entire map for the three closest vertices to your position.

Assuming that you have found the triangle, calculating a ray down to the ground would not be necessary. All you would have to take into consideration is your Y coord of your character and the Y coord at the ground. If the Y coord of the character is ever less than that of the ground, then you would just set the Y coord to equal that of the ground to make the character not fall through (and so it would not render the character partially in the ground). That really only needs to be done if the character leaves the ground. Otherwise, just set the character''s Y coords equal to that of the ground all the time (I''ve already come up with a way to detect stairs, which also has to do with using a Graph).

Now, the cool thing about the Graph that I just mentioned is that when you start to render the land, once you reach a peak, you could just not render the backside of the hill because each vertices knows what each vertice that it is connected to is, and it can detect if the next triangle drops instead of raises. This way you don''t render anything that is not necessary. Also, it will make it easier if you want to calculate how the ground is rendered as it gets farther into the distance. The farther away, the less triangles that are really needed. It would be very easy using a Graph. It will also make it much easier to calculate anywhere the ground ends with relevence to the edge of the camera.

Also, if you were to go into a dungeon or something with a low ceiling, you could just keep track of the triangle above the character also. The only problem would be if you were to walk under something which has something else above it when you were first just under the thing in which was higher first. I''ll spend some time trying to figure this out first before I really ask about it.

Now, I do agree with the initial polygon test, but that could easily be avoided by having set spots where the player spawns which know exactly what the first 3 vertices are, and after each logoff, you could save the location they were in last with the 3 vetices that surround the character.

If this seems really wrong, please tell me. Any other suggestion would be great.

Share this post


Link to post
Share on other sites