class Collider

Inherits: Component

Physics object that can be interacted with in the physics world.

It can either block other physics objects, or act as a trigger. Trigger will report collision events, but won't actually prevent other physical objects from going through them.

This object is intended to remain static in the world. You /can/ move it, but it will not interact with the physics world correctly when moved. For that case use Rigidbody instead.

Public

Constructors

Collider

Collider(const HSceneObject &parent)

Methods

~Collider

virtual ~Collider() noexcept = default

SetIsTrigger

void SetIsTrigger(bool value)

Determines if the collider is a trigger.

Trigger collider will not prevent objects from going through its shapes but it will still report collision events.

GetIsTrigger

bool GetIsTrigger() const

SetMass

void SetMass(float mass)

Determines the mass of the collider shape.

Only relevant if the parent collider is part of a rigidbody. Ultimately this will determine the total mass, center of mass and inertia tensors of the parent rigidbody (if they're being calculated automatically).

GetMass

float GetMass() const

SetMaterial

void SetMaterial(const HPhysicsMaterial &material)

Determines the physical material of the collider shape.

The material determines how objects hitting the collider shape.

GetMaterial

HPhysicsMaterial GetMaterial() const

SetContactOffset

void SetContactOffset(float value)

Determines how far apart do two shapes need to be away from each other before the physics runtime starts generating repelling impulse for them.

This distance will be the sum of contact offsets of the two interacting objects. If objects are moving fast you can increase this value to start generating the impulse earlier and potentially prevent the objects from interpenetrating. This value is in meters. Must be positive and greater than rest offset.

Also see SetRestOffset().

GetContactOffset

float GetContactOffset() const

SetRestOffset

void SetRestOffset(float value)

Determines at what distance should two objects resting on one another come to an equilibrium.

The value used in the runtime will be the sum of rest offsets for both interacting objects. This value is in meters. Cannot be larger than contact offset.

Also see SetContactOffset().

GetRestOffset

float GetRestOffset() const

SetLayer

void SetLayer(u64 layer)

Determines the layer of the collider shape.

Layer controls with which shapes will this shape collide.

GetLayer

u64 GetLayer() const

SetCollisionReportMode

void SetCollisionReportMode(CollisionReportMode mode)

Determines which (if any) collision events are reported.

GetCollisionReportMode

CollisionReportMode GetCollisionReportMode() const

GetRigidbody

HRigidbody GetRigidbody() const

Determines the Rigidbody that controls this collider (if any).

GetShapes

TInlineArray<SPtr<ColliderShape>, 1> GetShapes() const

Returns all the shapes associated with this collider.

RayCast

bool RayCast(const Ray &ray, PhysicsQueryHit &outHit, float maximumDistance = 3.40282347E+38F) const

Checks does the ray hit this collider.

ray
Ray to check.
outHit
Information about the hit. Valid only if the method returns true.
maximumDistance
Maximum distance from the ray origin to search for hits.

Returns: True if the ray has hit the collider.

RayCast

bool RayCast(const Vector3 &origin, const Vector3 &direction, PhysicsQueryHit &outHit, float maximumDistance = 3.40282347E+38F) const

Checks does the ray hit this collider.

origin
Origin of the ray to check.
direction
Unit direction of the ray to check.
outHit
Information about the hit. Valid only if the method returns true.
maximumDistance
Maximum distance from the ray origin to search for hits.

Returns: True if the ray has hit the collider.

staticGetRttiStatic

static RTTIType *GetRttiStatic()

GetRtti

RTTIType *GetRtti() const override

Returns an interface you can use to access class' Run Time Type Information.

Fields

OnCollisionBegin

Event<void (const CollisionData &)> OnCollisionBegin

Triggered when some object starts interacting with the collider.

Only triggered if proper collision report mode is turned on.

OnCollisionStay

Event<void (const CollisionData &)> OnCollisionStay

Triggered for every frame that an object remains interacting with a collider.

Only triggered if proper collision report mode is turned on.

OnCollisionEnd

Event<void (const CollisionData &)> OnCollisionEnd

Triggered when some object stops interacting with the collider.

Only triggered if proper collision report mode is turned on.

Internal

Methods

GetAdjustedPosition

const Vector3 &GetAdjustedPosition() const

GetAdjustedRotation

const Quaternion &GetAdjustedRotation() const

Protected

Constructors

Collider

Collider()

Methods

OnCreated

void OnCreated() override

Called once when the component has been created.

Called regardless of the state the component is in.

OnDestroyed

void OnDestroyed() override

Called once just before the component is destroyed.

Called regardless of the state the component is in.

OnDisabled

void OnDisabled() override

Called every time a component is placed into the Stopped state.

This includes component destruction if component wasn't already in Stopped state during destruction. When called during destruction it is called before OnDestroyed.

OnEnabled

void OnEnabled() override

Called every time a component leaves the Stopped state, if the component is enabled.

This includes component creation if requirements for leaving the Stopped state are met. When called during creation it is called after OnBeginPlay.

OnTransformChanged

void OnTransformChanged(TransformChangedFlags flags) override

Called when the component's parent scene object has changed.

Not called if the component is in Stopped state. Also only called if necessary notify flags are set via SetNotifyFlagsInternal().

IsValidParent

virtual bool IsValidParent(const HRigidbody &parent) const

Checks is the provided rigidbody a valid parent for this collider.

SetRigidbody

bool SetRigidbody(const HRigidbody &rigidbody)

Changes the rigidbody parent of the collider.

When set all shapes are parented to this rigidbody instead of the body backed by internal collider implementation. Returns true if the provided rigidbody is different from existing one.

UpdateTransform

void UpdateTransform(bool updateShapeTransforms = true)

Updates the transform of the internal collider representation from the transform of the component's scene object.

Optionally also updates all shape transforms as they may have changed if they depend on the parent.

UpdateCollisionReportMode

void UpdateCollisionReportMode()

Applies the collision report mode to the internal collider depending on the current state.

RefreshParentRigidbody

bool RefreshParentRigidbody()

Searches the parent scene object hierarchy to find a parent Rigidbody component, and determines if shapes need to be detached/attached if the parent rigidbody changed, was added or removed.

Returns true if parent changed.

Fields

mShapes

TInlineArray<SPtr<ColliderShape>, 1> mShapes

mImplementation

UPtr<IColliderImplementation> mImplementation

mLayer

u64 mLayer

mCollisionReportMode

CollisionReportMode mCollisionReportMode

mRestOffset

float mRestOffset

mContactOffset

float mContactOffset

mMaterial

HPhysicsMaterial mMaterial

mMass

float mMass

mIsTrigger

bool mIsTrigger

mParentRigidbody

HRigidbody mParentRigidbody

mAdjustedPosition

Vector3 mAdjustedPosition

mAdjustedRotation

Quaternion mAdjustedRotation