Corgi Engine  v8.8
MoreMountains.CorgiEngine.WeaponAutoAim Class Reference

This component will let you setup your weapon so that it auto aims at targets on the specified layer mask, within the specified radius, and with a line of sight. When a target is found, the weapon will swap its default aim mode to Script, until no more target is found. It's important to have a base aim mode to revert to, such as PrimaryMovement More...

Inheritance diagram for MoreMountains.CorgiEngine.WeaponAutoAim:
MoreMountains.CorgiEngine.CorgiMonoBehaviour

Public Types

enum  AimOrigins { AimOrigins.Weapon, AimOrigins.Owner }
 the possible origins to consider for the aim More...
 

Public Attributes

LayerMask TargetsMask = LayerManager.EnemiesLayerMask
 the layermask on which to look for aim targets More...
 
LayerMask ObstacleMask = LayerManager.ObstaclesLayerMask
 the layermask on which to look for obstacles More...
 
AimOrigins AimOrigin = AimOrigins.Weapon
 the object to consider as the origin of the aim More...
 
float ScanRadius = 15f
 the radius (in units) around the character within which to search for targets More...
 
Vector2 LineOfFireBoxcastSize = new Vector2(0.1f, 0.1f)
 the size of the boxcast that will be performed to verify line of fire More...
 
float DurationBetweenScans = 1f
 the duration (in seconds) between 2 scans for targets More...
 
Vector3 DetectionOriginOffset = Vector3.zero
 an offset to apply to the weapon's position for scan More...
 
bool DetectTriggers = false
 whether or not auto aim should detect trigger colliders More...
 
WeaponAim.RotationModes RotationMode
 the rotation mode to apply when a target is found More...
 
bool ToggleIgnoreSlopeRotation = false
 if this is true, the target WeaponAim's IgnoreSlopeRotation will be turned on/off depending on whether or not we have a target More...
 
bool MoveCameraTarget = true
 whether or not this component should take control of the camera target when a camera is found More...
 
float CameraTargetDistance = 0.5f
 the normalized distance (between 0 and 1) at which the camera target should be, on a line going from the weapon owner (0) to the auto aim target (1) More...
 
float CameraTargetMaxDistance = 10f
 the maximum distance from the weapon owner at which the camera target can be More...
 
float CameraTargetSpeed = 5f
 the speed at which to move the camera target More...
 
AimMarker AimMarkerPrefab
 An AimMarker prefab to use to show where this auto aim weapon is aiming. More...
 
MMFeedbacks FirstTargetFoundFeedback
 A feedback to play when a target is found and we didn't have one already. More...
 
MMFeedbacks NewTargetFoundFeedback
 a feedback to play when we already had a target and just found a new one More...
 
MMFeedbacks NoMoreTargetsFeedback
 a feedback to play when no more targets are found, and we just lost our last target More...
 
Transform Target
 the current target of the auto aim module More...
 
bool DrawDebugRadius = true
 whether or not to draw a debug sphere around the weapon to show its aim radius More...
 

Protected Member Functions

virtual void Start ()
 On Awake we initialize our component More...
 
virtual void Initialization ()
 On init we grab our WeaponAim More...
 
virtual void Update ()
 On Update, we setup our ray origin, scan periodically and set aim if needed More...
 
virtual void DetermineRaycastOrigin ()
 A method used to compute the origin of the detection casts More...
 
virtual bool ScanForTargets ()
 This method should define how the scan for targets is performed More...
 
virtual void SetAim ()
 Sends aim coordinates to the weapon aim component More...
 
virtual void HandleTargetChange ()
 Checks for target changes and triggers the appropriate methods if needed More...
 
virtual void HandleToggleIgnoreSlopeRotation ()
 
virtual void NoMoreTargets ()
 When no more targets are found, and we just lost one, we play a dedicated feedback More...
 
virtual void FirstTargetFound ()
 When a new target is found and we didn't have one already, we play a dedicated feedback More...
 
virtual void NewTargetFound ()
 When a new target is found, and we previously had another, we play a dedicated feedback More...
 
virtual void HandleMoveCameraTarget ()
 Moves the camera target towards the auto aim target if needed More...
 
virtual void ScanIfNeeded ()
 Performs a periodic scan More...
 
virtual void HandleTarget ()
 Sets aim if needed, otherwise reverts to the previous aim control mode More...
 
virtual void OnDrawGizmos ()
 Draws a sphere around the weapon to show its auto aim radius More...
 
virtual void OnDisable ()
 On Disable, we hide our aim marker if needed More...
 

Protected Attributes

float _lastScanTimestamp = 0f
 
WeaponAim _weaponAim
 
WeaponAim.AimControls _originalAimControl
 
WeaponAim.RotationModes _originalRotationMode
 
Vector3 _raycastOrigin
 
Weapon _weapon
 
bool _originalMoveCameraTarget
 
Vector3 _newCamTargetPosition
 
Vector3 _newCamTargetDirection
 
Character _character
 
List< Collider2D > _detectionColliders
 
Vector2 _facingDirection
 
Vector3 _boxcastDirection
 
Vector3 _aimDirection
 
ContactFilter2D _contactFilter
 
Collider2D _potentialHit
 
bool _initialized = false
 
Transform _targetLastFrame
 
AimMarker _aimMarker
 

Detailed Description

This component will let you setup your weapon so that it auto aims at targets on the specified layer mask, within the specified radius, and with a line of sight. When a target is found, the weapon will swap its default aim mode to Script, until no more target is found. It's important to have a base aim mode to revert to, such as PrimaryMovement

Member Enumeration Documentation

◆ AimOrigins

the possible origins to consider for the aim

Enumerator
Weapon 
Owner 

Member Function Documentation

◆ DetermineRaycastOrigin()

virtual void MoreMountains.CorgiEngine.WeaponAutoAim.DetermineRaycastOrigin ( )
protectedvirtual

A method used to compute the origin of the detection casts

◆ FirstTargetFound()

virtual void MoreMountains.CorgiEngine.WeaponAutoAim.FirstTargetFound ( )
protectedvirtual

When a new target is found and we didn't have one already, we play a dedicated feedback

◆ HandleMoveCameraTarget()

virtual void MoreMountains.CorgiEngine.WeaponAutoAim.HandleMoveCameraTarget ( )
protectedvirtual

Moves the camera target towards the auto aim target if needed

◆ HandleTarget()

virtual void MoreMountains.CorgiEngine.WeaponAutoAim.HandleTarget ( )
protectedvirtual

Sets aim if needed, otherwise reverts to the previous aim control mode

◆ HandleTargetChange()

virtual void MoreMountains.CorgiEngine.WeaponAutoAim.HandleTargetChange ( )
protectedvirtual

Checks for target changes and triggers the appropriate methods if needed

◆ HandleToggleIgnoreSlopeRotation()

virtual void MoreMountains.CorgiEngine.WeaponAutoAim.HandleToggleIgnoreSlopeRotation ( )
protectedvirtual

◆ Initialization()

virtual void MoreMountains.CorgiEngine.WeaponAutoAim.Initialization ( )
protectedvirtual

On init we grab our WeaponAim

◆ NewTargetFound()

virtual void MoreMountains.CorgiEngine.WeaponAutoAim.NewTargetFound ( )
protectedvirtual

When a new target is found, and we previously had another, we play a dedicated feedback

◆ NoMoreTargets()

virtual void MoreMountains.CorgiEngine.WeaponAutoAim.NoMoreTargets ( )
protectedvirtual

When no more targets are found, and we just lost one, we play a dedicated feedback

◆ OnDisable()

virtual void MoreMountains.CorgiEngine.WeaponAutoAim.OnDisable ( )
protectedvirtual

On Disable, we hide our aim marker if needed

◆ OnDrawGizmos()

virtual void MoreMountains.CorgiEngine.WeaponAutoAim.OnDrawGizmos ( )
protectedvirtual

Draws a sphere around the weapon to show its auto aim radius

◆ ScanForTargets()

virtual bool MoreMountains.CorgiEngine.WeaponAutoAim.ScanForTargets ( )
protectedvirtual

This method should define how the scan for targets is performed

Returns

◆ ScanIfNeeded()

virtual void MoreMountains.CorgiEngine.WeaponAutoAim.ScanIfNeeded ( )
protectedvirtual

Performs a periodic scan

◆ SetAim()

virtual void MoreMountains.CorgiEngine.WeaponAutoAim.SetAim ( )
protectedvirtual

Sends aim coordinates to the weapon aim component

◆ Start()

virtual void MoreMountains.CorgiEngine.WeaponAutoAim.Start ( )
protectedvirtual

On Awake we initialize our component

◆ Update()

virtual void MoreMountains.CorgiEngine.WeaponAutoAim.Update ( )
protectedvirtual

On Update, we setup our ray origin, scan periodically and set aim if needed

Member Data Documentation

◆ _aimDirection

Vector3 MoreMountains.CorgiEngine.WeaponAutoAim._aimDirection
protected

◆ _aimMarker

AimMarker MoreMountains.CorgiEngine.WeaponAutoAim._aimMarker
protected

◆ _boxcastDirection

Vector3 MoreMountains.CorgiEngine.WeaponAutoAim._boxcastDirection
protected

◆ _character

Character MoreMountains.CorgiEngine.WeaponAutoAim._character
protected

◆ _contactFilter

ContactFilter2D MoreMountains.CorgiEngine.WeaponAutoAim._contactFilter
protected

◆ _detectionColliders

List<Collider2D> MoreMountains.CorgiEngine.WeaponAutoAim._detectionColliders
protected

◆ _facingDirection

Vector2 MoreMountains.CorgiEngine.WeaponAutoAim._facingDirection
protected

◆ _initialized

bool MoreMountains.CorgiEngine.WeaponAutoAim._initialized = false
protected

◆ _lastScanTimestamp

float MoreMountains.CorgiEngine.WeaponAutoAim._lastScanTimestamp = 0f
protected

◆ _newCamTargetDirection

Vector3 MoreMountains.CorgiEngine.WeaponAutoAim._newCamTargetDirection
protected

◆ _newCamTargetPosition

Vector3 MoreMountains.CorgiEngine.WeaponAutoAim._newCamTargetPosition
protected

◆ _originalAimControl

WeaponAim.AimControls MoreMountains.CorgiEngine.WeaponAutoAim._originalAimControl
protected

◆ _originalMoveCameraTarget

bool MoreMountains.CorgiEngine.WeaponAutoAim._originalMoveCameraTarget
protected

◆ _originalRotationMode

WeaponAim.RotationModes MoreMountains.CorgiEngine.WeaponAutoAim._originalRotationMode
protected

◆ _potentialHit

Collider2D MoreMountains.CorgiEngine.WeaponAutoAim._potentialHit
protected

◆ _raycastOrigin

Vector3 MoreMountains.CorgiEngine.WeaponAutoAim._raycastOrigin
protected

◆ _targetLastFrame

Transform MoreMountains.CorgiEngine.WeaponAutoAim._targetLastFrame
protected

◆ _weapon

Weapon MoreMountains.CorgiEngine.WeaponAutoAim._weapon
protected

◆ _weaponAim

WeaponAim MoreMountains.CorgiEngine.WeaponAutoAim._weaponAim
protected

◆ AimMarkerPrefab

AimMarker MoreMountains.CorgiEngine.WeaponAutoAim.AimMarkerPrefab

An AimMarker prefab to use to show where this auto aim weapon is aiming.

◆ AimOrigin

AimOrigins MoreMountains.CorgiEngine.WeaponAutoAim.AimOrigin = AimOrigins.Weapon

the object to consider as the origin of the aim

◆ CameraTargetDistance

float MoreMountains.CorgiEngine.WeaponAutoAim.CameraTargetDistance = 0.5f

the normalized distance (between 0 and 1) at which the camera target should be, on a line going from the weapon owner (0) to the auto aim target (1)

◆ CameraTargetMaxDistance

float MoreMountains.CorgiEngine.WeaponAutoAim.CameraTargetMaxDistance = 10f

the maximum distance from the weapon owner at which the camera target can be

◆ CameraTargetSpeed

float MoreMountains.CorgiEngine.WeaponAutoAim.CameraTargetSpeed = 5f

the speed at which to move the camera target

◆ DetectionOriginOffset

Vector3 MoreMountains.CorgiEngine.WeaponAutoAim.DetectionOriginOffset = Vector3.zero

an offset to apply to the weapon's position for scan

◆ DetectTriggers

bool MoreMountains.CorgiEngine.WeaponAutoAim.DetectTriggers = false

whether or not auto aim should detect trigger colliders

◆ DrawDebugRadius

bool MoreMountains.CorgiEngine.WeaponAutoAim.DrawDebugRadius = true

whether or not to draw a debug sphere around the weapon to show its aim radius

◆ DurationBetweenScans

float MoreMountains.CorgiEngine.WeaponAutoAim.DurationBetweenScans = 1f

the duration (in seconds) between 2 scans for targets

◆ FirstTargetFoundFeedback

MMFeedbacks MoreMountains.CorgiEngine.WeaponAutoAim.FirstTargetFoundFeedback

A feedback to play when a target is found and we didn't have one already.

◆ LineOfFireBoxcastSize

Vector2 MoreMountains.CorgiEngine.WeaponAutoAim.LineOfFireBoxcastSize = new Vector2(0.1f, 0.1f)

the size of the boxcast that will be performed to verify line of fire

◆ MoveCameraTarget

bool MoreMountains.CorgiEngine.WeaponAutoAim.MoveCameraTarget = true

whether or not this component should take control of the camera target when a camera is found

◆ NewTargetFoundFeedback

MMFeedbacks MoreMountains.CorgiEngine.WeaponAutoAim.NewTargetFoundFeedback

a feedback to play when we already had a target and just found a new one

◆ NoMoreTargetsFeedback

MMFeedbacks MoreMountains.CorgiEngine.WeaponAutoAim.NoMoreTargetsFeedback

a feedback to play when no more targets are found, and we just lost our last target

◆ ObstacleMask

LayerMask MoreMountains.CorgiEngine.WeaponAutoAim.ObstacleMask = LayerManager.ObstaclesLayerMask

the layermask on which to look for obstacles

◆ RotationMode

WeaponAim.RotationModes MoreMountains.CorgiEngine.WeaponAutoAim.RotationMode

the rotation mode to apply when a target is found

◆ ScanRadius

float MoreMountains.CorgiEngine.WeaponAutoAim.ScanRadius = 15f

the radius (in units) around the character within which to search for targets

◆ Target

Transform MoreMountains.CorgiEngine.WeaponAutoAim.Target

the current target of the auto aim module

◆ TargetsMask

LayerMask MoreMountains.CorgiEngine.WeaponAutoAim.TargetsMask = LayerManager.EnemiesLayerMask

the layermask on which to look for aim targets

◆ ToggleIgnoreSlopeRotation

bool MoreMountains.CorgiEngine.WeaponAutoAim.ToggleIgnoreSlopeRotation = false

if this is true, the target WeaponAim's IgnoreSlopeRotation will be turned on/off depending on whether or not we have a target


The documentation for this class was generated from the following file: