S&box Wiki

Custom Physics on a ModelEntity

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.

public override void Spawn() { base.Spawn(); SetupPhysicsFromOrientedCapsule( PhysicsMotionType.Keyframed, Capsule.FromHeightAndRadius(72, 8) ); }
Don't call SetupPhysicsFrom____ on an entity that is not positioned at the origin, the physics body will be offset from the entity.

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.