Skip to content
EvilEngine.Formats.Collision

CollisionContent record

public sealed record CollisionContent

Converted collision content: the shapes something collides with, and what it weighs. A model’s is <model>/collision, made from Source’s .phy for Garry’s Mod, and a Plugin makes its own to give BodySpec for IPhysicsWorld.Add. Every length is in metres on Godot’s axes, about the body’s origin.

A box crate and a ball, each one Collider:

using System.Numerics;
using EvilEngine.Api.Physics;
using EvilEngine.Formats.Collision;
using EvilEngine.Formats.Maps;

var crate = new CollisionContent([new Collider(new ColliderShape.Box(new Vector3(0.8f, 0.8f, 0.8f)), ["solid"])]);
var ball = new CollisionContent([new Collider(new ColliderShape.Sphere(0.25f), ["solid"])])
{
    Motion = new CollisionMotion { Mass = 2 }
};

context.Physics?.Add(new BodySpec(crate) { Position = new MapVector(0, 2, 0), Mass = 30 });
context.Physics?.Add(new BodySpec(ball) { Position = new MapVector(1, 2, 0) });

A collision of several colliders is one rigid body of all of them, each placed by its own Position and Rotation. A dynamic body takes only convex shapes, so one holding a Mesh can only be static or kinematic.

Assembly
EvilEngine.Formats
Commit
4ff877b1

Members

CollisionContent constructor

public CollisionContent(IReadOnlyList<Collider> Colliders)

Makes a collision of colliders, with no motion and no jointed bodies.

Empty field

public static readonly CollisionContent Empty

A collision with no colliders, what something that collides with nothing has.

Colliders property

public IReadOnlyList<Collider> Colliders { get; init; }

The colliders, each a shape, what it’s made of and where it sits. A jointed collision’s Bodies name them by their index here.

Motion property

public CollisionMotion? Motion { get; init; }

The CollisionMotion of a collision that’s one moving body, or null. Only its mass is read: IPhysicsWorld.Add gives a body it, unless BodySpec.Mass is set. Source’s .phy gives one for a prop of one solid, with the solid’s mass. A jointed collision has none: each of its bodies gives its own mass.

Bodies property

public IReadOnlyList<CollisionBody> Bodies { get; init; }

A jointed collision’s bodies, such as a ragdoll’s parts, each owning some of the Colliders. Empty for a collision that’s one body. Every collider must be in exactly one body for it to be written. IPhysicsWorld.Add doesn’t read them and makes one body of every collider. A death ragdoll is made from them by the host, one physics body for each, and Source’s .phy gives them for a model with more than one solid.

Joints property

public IReadOnlyList<CollisionJoint> Joints { get; init; }

The joints between Bodies, each joining two of them by index. Empty unless the collision is jointed.

Jointed property

public bool Jointed { get; }

Whether the collision has Bodies, so it’s a set of jointed parts rather than one body.