• The PhysicsComponent is responsible for loading the physics shape and creating an actor for the Physics system to use. It is also responsible for updating an Entity’s position and rotation when it receives changes to the physics actor from the Physics system. If you’d like your model to respond to gravity, you will need it to have a PhysicsComponent. (If you choose to use a PhantomPhysicsComponent, then your physics are immovable). 
  • Giving an Entity its own physics
    • Once again you’ll want to go back to SampleScene.cs, and in the BoxStack () function you will find this line of code:
      PhysicsComponent newPhysComponent = new PhysicsComponent(newEntity, ShapeType.Box, 2, true);

      This will create a PhysicsComponent, attach it to the Entity ‘newEntity’ (in this case), tell it what shape it is (currently primitives/terrain only) which in this case is a Box/Cube, and give it a density. This will create a PhysicsActor for the component which the Physics system will need to process the physics for this Entity.
    • If you want to use a custom physics shape, there are three ways to do this.
      • If you want to load dynamically, for ShapeType, use ShapeType.TriangleMesh. This will work automatically if the RenderComponent has already been added to the entity.
      • If you want to use TriangleMesh without a render component, you can specify the model’s path instead of a ShapeType:
        PhysicsComponent newPhysComponent = new PhysicsComponent(newEntity, "Models/ship", 2, false);
      • If you're using a definition XML file, for ShapeType specify 'TriangleMesh', then for PhysicsModelPath specify the model file you want to use for the shape. For an example of this look in 'Content/Entities/ComponentDefinitions/Physics/SpaceshipPhysics.xml'.

Last edited Jan 5, 2012 at 5:34 AM by LordIkon, version 1


No comments yet.