Jump to content
  • Advertisement
Sign in to follow this  
215648

walk on terrain mesh

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

how to make the camera/character/model walk on terrain if it's not a heightmap but just a simple terrain mesh designed in 3d modeling software like 3ds max and blender.

Share this post


Link to post
Share on other sites
Advertisement

You can use NVIDIA PhysX, it has a character controller, it provides a capsule shape which will move around overtop of an arbitrary mesh (i.e. the ground terrain mesh you have), it will also slide against walls.

The terrain, in PhysX, would be constructed by reading out the triangles that comprise the terrain mesh and passing them into a PxTriangleMeshDesc then into cookTriangleMesh.

From there, you'd just position the capsule controller above the ground and drop it and use keyboard controls (WASD) to move it around (based on your characters forward direction).

Share this post


Link to post
Share on other sites

Figured out :

void WalkOnTerrain()
{
	D3DXVECTOR3 pos;
	Cam.GetPosition(&pos);

	D3DXVECTOR3 org = pos + D3DXVECTOR3(0.0f, 10.0f, 0.0f);
	D3DXVECTOR3 dir = D3DXVECTOR3(0.0f, -1.0f, 0.0f);

	BOOL Hit;
	DWORD FaceIndex;
	FLOAT U;
	FLOAT V;
	float Dist;

	D3DXIntersect(Map.GetMesh(),
		&org,
		&dir,
		&Hit,
		&FaceIndex,
		&U,
		&V,
		&Dist,
		0,
		0);

	if (Hit)
	{
		Cam.SetPosition(&D3DXVECTOR3(pos.x, org.y - Dist, pos.z)); // = org.y - Dist;
	}
}

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!