walk on terrain mesh

Started by
1 comment, last by 215648 10 years, 5 months ago

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.

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

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;
	}
}

This topic is closed to new replies.

Advertisement