Jump to content
  • Advertisement
Sign in to follow this  
Feadur

Make a model follow the terrain

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

First of all, sorry about my english (it's not my language actually). I'm pretty shure this question has been answered before, but since I cannot find it, I'll make it again. I have two meshes, one for the terrain, and one for the character (in fact, it is the "tiny.x" model that ships with the DirectX SDK). There's no problem if i make the character move along the terrain, as long as it is a plane, but, how can it detects when the terrain mesh is not a plane and so, move the model along the Y axis? I cannot use bounding sphere and standard collision test, because de character mesh bounding sphere is always inside the terrain mesh bounding sphere. I'm workin with c# and DirectX 9 Thanks in advance ;)

Share this post


Link to post
Share on other sites
Advertisement
Are you trying to orient your model to the plane angle when its slanted or like a slope ? If so you need to do ray/sphere plane collision and get the angle using the dot product and axis or rotation using cross product.

Hope this helps.

Share this post


Link to post
Share on other sites
Actually that's what I'm trying to do. But I have no clue on how to do it. Do you have any example -web link, or wathever- of ray/sphere plane collision?

Thanks

I'll try to search thought gamedev anyway.

Share this post


Link to post
Share on other sites
Thanks Ocelot. That's what I'm trying to do, but since I don't understand C++, I can't extract any idea from it :(

And even if I can run the compiled example, the code doesn't compile on Visual Studio 2005.

Share this post


Link to post
Share on other sites
Thanks Crack123, it's a good starting point, but as it says in that tutorial, I have to compare the distance between the sphere and the plane with the bounding sphere radius, where

distance = plane.normal · sphere.position

The problem is how to calculate the plane normal, because I know how to calculate the normal given a plane, but my terrain IS NOT a single plane. Instead, is a polygonal mesh with lots of vertices and planes, and I need to know which plane is te bounding sphere over. Also, it can be colliding with multiple planes at the same time. For example, a building in the middle of the terrain would make 2 collisions. the one with the floor, and the other with the building's wall.

Share this post


Link to post
Share on other sites
Ok, but the problem is that I don't know how to get the plane where the model is over, since the terrain is also a mesh.

Is there any function in DirectX 9 that gives me the plane from the mesh A to which mesh B is closer?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!