S&box Wiki

Revision Difference

custom-physic-setup#548355

<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 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) ); } ``` ⤶ ⤶ <warning>⤶ Don't call `SetupPhysicsFrom____` on an entity that is not positioned at the origin, the physics body will be offset from the entity.⤶ </warning>⤶ # 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.