• Create Account

## Moving on surface

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

11 replies to this topic

### #1DmitryNik  Members

199
Like
0Likes
Like

Posted 23 November 2012 - 06:18 AM

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?

Edited by DmitryNik, 23 November 2012 - 06:21 AM.

### #2DmitryNik  Members

199
Like
0Likes
Like

Posted 23 November 2012 - 06:22 AM

p.s. in Attachments could be found a figure that demonstrates, what did I mean=) Real surface is a bit more complicated.

### #3Yrjö P.  Members

1416
Like
1Likes
Like

Posted 23 November 2012 - 06:45 AM

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.

### #4DmitryNik  Members

199
Like
0Likes
Like

Posted 23 November 2012 - 07:35 AM

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

### #5Tispe  Members

1417
Like
0Likes
Like

Posted 23 November 2012 - 07:53 AM

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, 23 November 2012 - 07:59 AM.

### #6Yrjö P.  Members

1416
Like
1Likes
Like

Posted 23 November 2012 - 08:03 AM

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

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.

### #7DmitryNik  Members

199
Like
0Likes
Like

Posted 23 November 2012 - 11:36 AM

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?

Edited by DmitryNik, 23 November 2012 - 11:37 AM.

### #8DmitryNik  Members

199
Like
0Likes
Like

Posted 23 November 2012 - 11:45 AM

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

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.

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.

3217
Like
1Likes
Like

Posted 23 November 2012 - 01:25 PM

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.

### #10DmitryNik  Members

199
Like
0Likes
Like

Posted 23 November 2012 - 03:38 PM

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(buggy ) engine, I'll learn things faster =)

3217
Like
0Likes
Like

Posted 23 November 2012 - 03:59 PM

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.

### #12DmitryNik  Members

199
Like
0Likes
Like

Posted 24 November 2012 - 05:14 AM

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.

That is true too.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.