• Advertisement

# Moving on surface

This topic is 1881 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

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. Edited by DmitryNik

#### Share this post

##### Share on other sites
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]

#### Share this post

##### Share on other sites
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.

#### Share this post

##### Share on other sites
[quote name='Stroppy Katamari' timestamp='1353674710' post='5003474']
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.
[/quote]

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.?

#### Share this post

##### Share on other sites
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 Edited by Tispe

#### Share this post

##### Share on other sites
[quote name='DmitryNik' timestamp='1353677719' post='5003489']
But what about flying and falling off the cliffs etc.?
[/quote]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.

#### Share this post

##### Share on other sites
[quote name='Tispe' timestamp='1353678786' post='5003493']
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
[/quote]

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? Edited by DmitryNik

#### Share this post

##### Share on other sites
[quote name='Stroppy Katamari' timestamp='1353679415' post='5003498']
[quote name='DmitryNik' timestamp='1353677719' post='5003489']
But what about flying and falling off the cliffs etc.?
[/quote]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.

#### Share this post

##### Share on other sites
Something like doing a swept ellipsoid collision detection/response might work:

[url="http://www.peroxide.dk/download/tutorials/tut10/pxdtut10.html"]http://www.peroxide....0/pxdtut10.html[/url]
[url="http://www.three14.demon.nl/sweptellipsoid/SweptEllipsoid.pdf"]http://www.three14.demon.nl/sweptellipsoid/SweptEllipsoid.pdf[/url]

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

#### Share this post

##### Share on other sites
[quote name='shadowisadog' timestamp='1353698746' post='5003565']
Something like doing a swept ellipsoid collision detection/response might work:

[url="http://www.peroxide.dk/download/tutorials/tut10/pxdtut10.html"]http://www.peroxide....0/pxdtut10.html[/url]
[url="http://www.three14.demon.nl/sweptellipsoid/SweptEllipsoid.pdf"]http://www.three14.d...ptEllipsoid.pdf[/url]

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

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(buggy[img]http://public.gamedev.net//public/style_emoticons/default/rolleyes.gif[/img] ) engine, I'll learn things faster =)

#### Share this post

##### Share on other sites
I view existing engines as an excellent starting point.

Technology progresses when we build off of the work of others. Constantly reinventing wheels can teach a lot, but in the terms of actually accomplishing greater things, what does it really do?

In a number of cases these engines are the products of years or even decades of work...

In the end the question must be what do you hope to accomplish? If it is to learn how to do collision detection and response then by all means implement it yourself, but if you wish to make games then using existing technology is a fantastic idea.

If nothing else in several years or with time why not contribute to an open source existing physics engine? That way you could advance the technology and not start from scratch.

Just my two cents. Edited by shadowisadog

#### Share this post

##### Share on other sites
[quote name='shadowisadog' timestamp='1353707961' post='5003588']
I view existing engines as an excellent starting point.

Technology progresses when we build off of the work of others. Constantly reinventing wheels can teach a lot, but in the terms of actually accomplishing greater things, what does it really do?

In a number of cases these engines are the products of years or even decades of work...

In the end the question must be what do you hope to accomplish? If it is to learn how to do collision detection and response then by all means implement it yourself, but if you wish to make games then using existing technology is a fantastic idea.

If nothing else in several years or with time why not contribute to an open source existing physics engine? That way you could advance the technology and not start from scratch.

Just my two cents.
[/quote]

That is true too.

#### Share this post

##### Share on other sites

• Advertisement