S&box Wiki

Revision Difference

custom-physic-setup#548192

<cat>Code.Physics</cat> <title>Custom Physics on a ModelEntity</title> # Using colliders that are not models When creating a `ModelEntity` you can decide to use a collider that is not based on the entities model. For instance you may create an entity which uses the citizen model, but has a capsule collider. When creating a `ModelEntity` you can decide to use a collider that is not based on the entity's model. For instance, you may create an entity which uses the citizen model, but has a capsule collider. To do this you must call a `SetupPhysicsFrom____` method, for instance in the `Spawn()` method of an entity. ```cs public override void Spawn() { base.Spawn(); SetupPhysicsFromOrientedCapsule( PhysicsMotionType.Keyframed, Capsule.FromHeightAndRadius(72, 8) ); } ``` # Physics Motion Types There are three types of motion types you can choose from, `Dynamic`, `Static`, and `Keyframed`. Some colliders do not support the `Dynamic` motion type, such as AABB, cylinder, and capsule (you can use an oriented capsule however.) You can not circumvent this restriction by adjusting the `BodyType` of the physics body after it has been created. For instance, if you set `BodyType` of a capsule to `Dynamic` it's rotation will immediately be reset to zero.