I am making a 3D game right now and I need some help. Physics for camera and static objects like pyramids and temples work rather well. Problem is with making physics for enemies. I am using ConvexHull to represent them physically. But I don't know how to connect animations for them with their physical representations (Convex Hulls). Additionally (and more importantly) it looks like physics aren't connected with the graphical representations of enemies. When I am moving convex hull, the model doesn't move at all. I would like to have convex hulls, that cannot be rotated or moved by player, but they have to move when the characters are walking, running etc.
Here is the code:
Code: Select all
//Load in mesh data and create the group.
Vector3[] dynamicTriangleVertices;
int[] dynamicTriangleIndices;
Vector3 rotRad = (float)Math.PI / 180.0f * rot;
Quaternion rotationQuaternion = Quaternion.CreateFromYawPitchRoll(rotRad.Y, rotRad.X, rotRad.Z);
//This load method wraps the TriangleMesh.GetVerticesAndIndicesFromModel method
//to output vertices of type StaticTriangleGroupVertex instead of TriangleMeshVertex or simply Vector3.
TriangleMesh.GetVerticesAndIndicesFromModel(enemyModel, out dynamicTriangleVertices, out dynamicTriangleIndices);
Matrix world = Matrix.CreateFromQuaternion(rotationQuaternion) * Matrix.CreateScale(scale); //Matrix.CreateTranslation(pos);
ConvexHull convexHull = new ConvexHull(dynamicTriangleVertices, 10.0f);
TransformableShape transShape = new TransformableShape(convexHull.CollisionInformation.Shape, Matrix3X3.CreateFromMatrix(world));
Entity entity = new Entity(new ConvexCollidable<TransformableShape>(transShape), 10.0f, convexHull.LocalInertiaTensor, convexHull.Volume);
entity.Position = pos;
entity.Orientation = rotationQuaternion;
PhysicsManager.Instance.Space.Add(entity);
Game1.ModelDrawer.Add(entity);