SwingHitDetector

February 9, 2024 ยท View on GitHub

Namespace: Unity.TinyCharacterController.Utility


Summary:

SwingHitDetector is a component designed to detect and notify of collision events during actions such as swings, attacks, and movements, as well as collisions with other colliders. It performs collision detection based on a defined range and the movement path of the contact point, primarily intended for scenarios like weapon swing attacks and collision detection with traps.

Features and Operation:

  • Collision Detection Configuration: Sets up positions and sizes for collision detection.
  • Collision Event Notification: Notifies of detected collision events.

Properties

NameDescription
TimingThe timing for collision detection.
OwnerThe owner of this component.
CacheTargetTypeThe type of cached target.
HitLayerThe layer used for collision detection.
HitTagsAn array of tags for which collision detection is performed.
OnHitObjectsEvent triggered when colliding with objects.
_detectorPositionsPositions and sizes for collision detection.

Methods

NameFunction
Vector3 GetContactPosition( GameObject obj )Retrieves the position where the specified object made contact in the past.
Vector3 GetContactPosition( Collider col )Retrieves the position where the specified collider made contact in the past.

Additional Notes

  • SwingHitDetector inherits from CollisionDetectorBase, providing fundamental functionalities for collision detection.
  • Collision detection configurations are defined using the LineHitData structure, specifying detection positions and sizes.
  • Detected collision events are notified through the OnHitObjects event, allowing for triggering specific actions or reactions in response.