Moving on surface

Started by
10 comments, last by DmitryNik 11 years, 4 months ago
Hello!

I can bet, there are a lot of questions about how to do it. But due to the lack of skills "how to google right" I cannot find anything which could be useful for beginners in games programming. I've created a terrain from the height map and now I would like to create some strange creatures(like me =) ), which are moving around the surface. How can I make them move on surface according to the heights(y -coordinate): if there is a kind of hill, then creature is about to move on that hill smoothly, not just through this hill. At this moment my camera can move easily through the hills and surely surface itself. So surface only looks solid. So, my question is, how can I make the terrain really(as much as it possible in games world) solid that all creatures are able to move along all curves, hills and will not be able to go through those hills? Is there any specific algorithms and theories? Is it only about collision detection with the surface?

Thank you for your answers beforehand.
Advertisement
p.s. in Attachments could be found a figure that demonstrates, what did I mean=) Real surface is a bit more complicated.
[attachment=12427:justincase.png]
If you don't need stuff jumping, flying, falling off cliffs etc., you could move your characters as if they are still moving on flat plane and just draw them to the height of the surface.

If you don't need stuff jumping, flying, falling off cliffs etc., you could move your characters as if they are still moving on flat plane and just draw them to the height of the surface.


Thank you for your answer. So, as I understood, I only have to translate creatures according to y-coordinate, when it's moving? OK, I thought it would be more difficult, but it seems that the easiest way is the right one always. OK.
But what about flying and falling off the cliffs etc.?
Maybe use D3DXIntersect() to determine the distance between the entity and the ground?

What it does is to take a Mesh and two vectors. It loops through the mesh (terrain) and checks if any of the triangles in the mesh collides with your vector. The results are in the out parameters.

Have your Entity position be the *pRayPos paramter, and the D3DXVECTOR3(0,-1,0) as the direction vector (straight down).

Or if you want to know the distance to translate your entity up and down. Use a distance from a plane much lower then the terrain and you can get the exact height of the terrain based on your entity planar position

But what about flying and falling off the cliffs etc.?
What about them?

If you need stuff like that, some of it can be "faked" in simple ways (that are competely legit to use as long as their limitations aren't critical for your game). For instance, you could have a helicopter always fly at a certain height above the terrain, in which case it would be no harder to do technically than other characters; many AAA RTS games do just that. Similar technique would handle characters jumping, and it would look OK as long as the terrain doesn't have steep slopes. The more sophisticated behaviors you need, the more stuff you have to implement.

One easy thing you might want to do with the terrain is to scale characters' movement speed according to whether they are going uphill; without that, their movement will seem very unnatural near steeper slopes. If you detected a very steep slope, you could also put the character in a "falling" state and handle that differently than normal movement. But if you increase complexity with special cases like that, at some point it'll becomes too much to hold together and you start needing actual collision detection and/or physics engines.

Maybe use D3DXIntersect() to determine the distance between the entity and the ground?

What it does is to take a Mesh and two vectors. It loops through the mesh (terrain) and checks if any of the triangles in the mesh collides with your vector. The results are in the out parameters.

Have your Entity position be the *pRayPos paramter, and the D3DXVECTOR3(0,-1,0) as the direction vector (straight down).

Or if you want to know the distance to translate your entity up and down. Use a distance from a plane much lower then the terrain and you can get the exact height of the terrain based on your entity planar position


Will it a bit slow? For instance, if I take a simple height map 128x128, then in this case there are about 16384 vertices and let's say 5461 triangles. it will definitely take too much time for checking. Is there another way? Will be position tracking for each character a good idea? How it was done earlier?

[quote name='DmitryNik' timestamp='1353677719' post='5003489']
But what about flying and falling off the cliffs etc.?
What about them?

If you need stuff like that, some of it can be "faked" in simple ways (that are competely legit to use as long as their limitations aren't critical for your game). For instance, you could have a helicopter always fly at a certain height above the terrain, in which case it would be no harder to do technically than other characters; many AAA RTS games do just that. Similar technique would handle characters jumping, and it would look OK as long as the terrain doesn't have steep slopes. The more sophisticated behaviors you need, the more stuff you have to implement.

One easy thing you might want to do with the terrain is to scale characters' movement speed according to whether they are going uphill; without that, their movement will seem very unnatural near steeper slopes. If you detected a very steep slope, you could also put the character in a "falling" state and handle that differently than normal movement. But if you increase complexity with special cases like that, at some point it'll becomes too much to hold together and you start needing actual collision detection and/or physics engines.
[/quote]

That one is a good answer.Yeah, I thought of using collision detection. That's actually nice, if I have to implement my own physics engine. Only in this case I can learn at least something.
Something like doing a swept ellipsoid collision detection/response might work:

http://www.peroxide....0/pxdtut10.html
http://www.three14.demon.nl/sweptellipsoid/SweptEllipsoid.pdf

Although an easier way would be to use an existing physics engine such as ODE, Bullet, or PhysX.

Something like doing a swept ellipsoid collision detection/response might work:

http://www.peroxide....0/pxdtut10.html
http://www.three14.d...ptEllipsoid.pdf

Although an easier way would be to use an existing physics engine such as ODE, Bullet, or PhysX.


Thank you for the links. Ready engines, in my opinion(I could be wrong), are not a good starting point, if I'd like to learn something. By making my own(buggyrolleyes.gif ) engine, I'll learn things faster =)

This topic is closed to new replies.

Advertisement