# collisions with terrain

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

## Recommended Posts

Hi, I would like to implement collisions with terrain in my game. but the problem is that terrain has mountains too!! so I would like to know if you have any guide or any tip to help me making my objects stop at mountains (or climb). I'm using Direct3D 9.0 with C# .NET thank you.

##### Share on other sites
.Raw file terrain?

start by writing a method which takes as input a position on the map (float/int/double X,Y) and returns the height of the ground at that point.

##### Share on other sites
Quote:
 Original post by TheUmpteenth.Raw file terrain?start by writing a method which takes as input a position on the map (float/int/double X,Y) and returns the height of the ground at that point.

well, I'm actually a beginner with this stuff... I didn't know anything about .raw terrain files

O.o well I'm gonna see what I can find on the net.

##### Share on other sites
I didn't find anything on raw terrain files....do you have any resources or guides?

##### Share on other sites
It took me a while to figure this one out too... I had to dig out some wonky algebra book that I remembered taking in school way back when. As it turns out, it was some very tricky(for me) parametric math that calculated to see if a vector intersected a triangle. Which it worked great... alas it's the getting the determinant of a 4x4(3x3?) matrix that was a hoot.

As stated above, have a point in triangle algorithm and that should get you atarted on the getHeightAtLocation() method for bumping around. There should be plenty abouts. Just think about liking at your terrain straight downwards and then you may be able to calculate it more easily with pile of 2d math on it.

I dunno... I just remember that solving this problem made me feel that my whole acedemic stay in school with respect to math was well worth it. I had one of them eureka moments y'know.

##### Share on other sites
There's a pretty good terrain creation tutorial with C# does a bruteforce method and a heightmapped method.
http://www.riemers.net/eng/Tutorials/DirectX/Csharp/Series1/tut7.php

Here's a link from M\$ Coding4Fun blog on terrain following.
http://blogs.msdn.com/coding4fun/archive/2006/11/09/1044454.aspx

DirectX 9.0c a shader approach or whatever it's called has a good section on this, I imagine the one before it would too if you don't like shaders. Andre' LaMothe's book Tricks of the 3D Game Programming Gurus also has a good section on terrain following suitable for bipedal characters.

##### Share on other sites
Well, I did it. Now i learnt how to use raw maps and I made a really basic function to calculate height, basing on a char array in which the raw map is loaded. But the problem is that height only changes when the camera coordinates are the same of a vertex, if camera is on a line which links two vertices or in any other point on the map, height is not calculated :/

So if you know any method to calculate height in a 3d space and you want to post it, I'll be thankful to you.

##### Share on other sites
Have you read any of the tutorials above..?

##### Share on other sites
of course I did, even if I must read better the second tutorial.

maybe the answer to my question is buried in that second tutorial..

but..why this question? O.o

##### Share on other sites
look up "ray/line intersecting a triangle", "equation of a plane" and "dot product". The line/ray (object up/down vector) is exactly vertical. Once you have your plane equation plug in your x and y position and out should come z.

1. 1
Rutin
44
2. 2
3. 3
4. 4
5. 5

• 10
• 9
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632983
• Total Posts
3009707
• ### Who's Online (See full list)

There are no registered users currently online

×