TopDown Engine  v3.6
MoreMountains.TopDownEngine.WeaponAim Class Reference
Inheritance diagram for MoreMountains.TopDownEngine.WeaponAim:
MoreMountains.TopDownEngine.TopDownMonoBehaviour MoreMountains.Tools.MMEventListener< TopDownEngineEvent > MoreMountains.Tools.MMMonoBehaviour MoreMountains.TopDownEngine.WeaponAim2D MoreMountains.TopDownEngine.WeaponAim3D

Public Types

enum  AimControls {
  AimControls.Off, AimControls.PrimaryMovement, AimControls.SecondaryMovement, AimControls.Mouse,
  AimControls.Script, AimControls.SecondaryThenPrimaryMovement, AimControls.PrimaryThenSecondaryMovement, AimControls.CharacterRotateCameraDirection
}
 the list of possible control modes More...
 
enum  RotationModes { RotationModes.Free, RotationModes.Strict2Directions, RotationModes.Strict4Directions, RotationModes.Strict8Directions }
 the list of possible rotation modes More...
 
enum  ReticleTypes { ReticleTypes.None, ReticleTypes.Scene, ReticleTypes.UI }
 the possible types of reticles More...
 

Public Member Functions

virtual void ApplyAim ()
 
virtual void SetCurrentAim (Vector3 newAim, bool setAimAsLastNonNullMovement=false)
 Aims the weapon towards a new point More...
 
virtual Vector3 GetReticlePosition ()
 Returns the position of the reticle More...
 
virtual Vector3 GetMousePosition ()
 Returns the current mouse position More...
 
virtual void RemoveReticle ()
 Removes any remaining reticle More...
 
virtual void AddAdditionalAngle (float addedAngle)
 Adds additional angle to the weapon's rotation More...
 
void OnMMEvent (TopDownEngineEvent engineEvent)
 
- Public Member Functions inherited from MoreMountains.Tools.MMEventListener< TopDownEngineEvent >
void OnMMEvent (T eventType)
 

Public Attributes

AimControls AimControl = AimControls.SecondaryMovement
 the aim control mode More...
 
bool AimControlActive = true
 if this is true, this script will be able to read input from its specified AimControl mode More...
 
RotationModes RotationMode = RotationModes.Free
 the rotation mode More...
 
float WeaponRotationSpeed = 1f
 the the speed at which the weapon reaches its new position. Set it to zero if you want movement to directly follow input More...
 
float MinimumAngle = -180f
 the minimum angle at which the weapon's rotation will be clamped More...
 
float MaximumAngle = 180f
 the maximum angle at which the weapon's rotation will be clamped More...
 
float MinimumMagnitude = 0.2f
 the minimum threshold at which the weapon's rotation magnitude will be considered More...
 
ReticleTypes ReticleType = ReticleTypes.None
 Defines whether the reticle is placed in the scene or in the UI. More...
 
GameObject Reticle
 the gameobject to display as the aim's reticle/crosshair. Leave it blank if you don't want a reticle More...
 
float ReticleDistance
 the distance at which the reticle will be from the weapon More...
 
float ReticleHeight
 the height at which the reticle should position itself above the ground, when in Scene mode More...
 
bool ReticleAtMousePosition
 if set to true, the reticle will be placed at the mouse's position (like a pointer) More...
 
bool RotateReticle = false
 if set to true, the reticle will rotate on itself to reflect the weapon's rotation. If not it'll remain stable. More...
 
bool ReplaceMousePointer = true
 if set to true, the reticle will replace the mouse pointer More...
 
float MouseDeadZoneRadius = 0.5f
 the radius around the weapon rotation centre where the mouse will be ignored, to avoid glitches More...
 
bool DisplayReticle = true
 if set to false, the reticle won't be added and displayed More...
 
bool MoveCameraTargetTowardsReticle = false
 whether the camera target should be moved towards the reticle to provide a better vision of the possible target. If you don't have a reticle, it'll be moved towards your aim direction. More...
 
float CameraTargetOffset = 0.3f
 the offset to apply to the camera target along the transform / reticle line More...
 
float CameraTargetMaxDistance = 10f
 the maximum distance at which to move the camera target More...
 
float CameraTargetSpeed = 5f
 the speed at which the camera target should be moved More...
 
virtual Weapon TargetWeapon => _weapon
 

Protected Member Functions

virtual void Start ()
 On Start(), we trigger the initialization More...
 
virtual void Initialization ()
 Grabs the weapon component, initializes the angle values More...
 
virtual void GetCurrentAim ()
 
virtual void Update ()
 Every frame, we compute the aim direction and rotate the weapon accordingly More...
 
virtual void LateUpdate ()
 On LateUpdate, resets any additional angle More...
 
virtual void DetermineWeaponRotation ()
 Determines the weapon's rotation More...
 
virtual void MoveReticle ()
 Moves the weapon's reticle More...
 
virtual void RotateWeapon (Quaternion newRotation, bool forceInstant=false)
 Rotates the weapon, optionnally applying a lerp to it. More...
 
virtual void AimAt (Vector3 target)
 
virtual void InitializeReticle ()
 If a reticle has been set, instantiates the reticle and positions it More...
 
virtual void MoveTarget ()
 This method defines how the character's camera target should move More...
 
virtual void HideReticle ()
 Hides (or shows) the reticle based on the DisplayReticle setting More...
 
virtual void HideMousePointer ()
 Hides or show the mouse pointer based on the settings More...
 
void OnDestroy ()
 On Destroy, we reinstate our cursor if needed More...
 
virtual void ResetAdditionalAngle ()
 Resets the additional angle More...
 
virtual void AutoDetectWeaponMode ()
 
virtual void OnEnable ()
 On enable we start listening for events More...
 
virtual void OnDisable ()
 On disable we stop listening for events More...
 

Protected Attributes

Camera _mainCamera
 
Vector2 _lastNonNullMovement
 
Weapon _weapon
 
Vector3 _currentAim = Vector3.zero
 
Vector3 _currentAimAbsolute = Vector3.zero
 
Quaternion _lookRotation
 
Vector3 _direction
 
float[] _possibleAngleValues
 
Vector3 _mousePosition
 
Vector3 _lastMousePosition
 
float _additionalAngle
 
Quaternion _initialRotation
 
Plane _playerPlane
 
GameObject _reticle
 
Vector3 _reticlePosition
 
Vector3 _newCamTargetPosition
 
Vector3 _newCamTargetDirection
 
bool _initialized = false
 
Vector3 _aimAtDirection
 
Quaternion _aimAtQuaternion
 

Properties

virtual float CurrentAngleAbsolute [get, protected set]
 
virtual Quaternion CurrentRotation [get]
 the weapon's current rotation More...
 
virtual Vector3 CurrentAim [get]
 the weapon's current direction More...
 
virtual Vector3 CurrentAimAbsolute [get]
 the weapon's current direction, absolute (flip independent) More...
 
virtual float CurrentAngle [get, protected set]
 the current angle the weapon is aiming at More...
 
virtual float CurrentAngleRelative [get]
 the current angle the weapon is aiming at, adjusted to compensate for the current orientation of the character More...
 

Member Enumeration Documentation

◆ AimControls

the list of possible control modes

Enumerator
Off 
PrimaryMovement 
SecondaryMovement 
Mouse 
Script 
SecondaryThenPrimaryMovement 
PrimaryThenSecondaryMovement 
CharacterRotateCameraDirection 

◆ ReticleTypes

the possible types of reticles

Enumerator
None 
Scene 
UI 

◆ RotationModes

the list of possible rotation modes

Enumerator
Free 
Strict2Directions 
Strict4Directions 
Strict8Directions 

Member Function Documentation

◆ AddAdditionalAngle()

virtual void MoreMountains.TopDownEngine.WeaponAim.AddAdditionalAngle ( float  addedAngle)
virtual

Adds additional angle to the weapon's rotation

Parameters
addedAngle

◆ AimAt()

virtual void MoreMountains.TopDownEngine.WeaponAim.AimAt ( Vector3  target)
protectedvirtual

◆ ApplyAim()

virtual void MoreMountains.TopDownEngine.WeaponAim.ApplyAim ( )
virtual

◆ AutoDetectWeaponMode()

virtual void MoreMountains.TopDownEngine.WeaponAim.AutoDetectWeaponMode ( )
protectedvirtual

◆ DetermineWeaponRotation()

virtual void MoreMountains.TopDownEngine.WeaponAim.DetermineWeaponRotation ( )
protectedvirtual

Determines the weapon's rotation

Reimplemented in MoreMountains.TopDownEngine.WeaponAim2D, and MoreMountains.TopDownEngine.WeaponAim3D.

◆ GetCurrentAim()

virtual void MoreMountains.TopDownEngine.WeaponAim.GetCurrentAim ( )
protectedvirtual

◆ GetMousePosition()

virtual Vector3 MoreMountains.TopDownEngine.WeaponAim.GetMousePosition ( )
virtual

Returns the current mouse position

◆ GetReticlePosition()

virtual Vector3 MoreMountains.TopDownEngine.WeaponAim.GetReticlePosition ( )
virtual

Returns the position of the reticle

Returns

◆ HideMousePointer()

virtual void MoreMountains.TopDownEngine.WeaponAim.HideMousePointer ( )
protectedvirtual

Hides or show the mouse pointer based on the settings

◆ HideReticle()

virtual void MoreMountains.TopDownEngine.WeaponAim.HideReticle ( )
protectedvirtual

Hides (or shows) the reticle based on the DisplayReticle setting

◆ Initialization()

virtual void MoreMountains.TopDownEngine.WeaponAim.Initialization ( )
protectedvirtual

Grabs the weapon component, initializes the angle values

Reimplemented in MoreMountains.TopDownEngine.WeaponAim3D, and MoreMountains.TopDownEngine.WeaponAim2D.

◆ InitializeReticle()

virtual void MoreMountains.TopDownEngine.WeaponAim.InitializeReticle ( )
protectedvirtual

If a reticle has been set, instantiates the reticle and positions it

Reimplemented in MoreMountains.TopDownEngine.WeaponAim2D, and MoreMountains.TopDownEngine.WeaponAim3D.

◆ LateUpdate()

virtual void MoreMountains.TopDownEngine.WeaponAim.LateUpdate ( )
protectedvirtual

On LateUpdate, resets any additional angle

◆ MoveReticle()

virtual void MoreMountains.TopDownEngine.WeaponAim.MoveReticle ( )
protectedvirtual

Moves the weapon's reticle

Reimplemented in MoreMountains.TopDownEngine.WeaponAim2D, and MoreMountains.TopDownEngine.WeaponAim3D.

◆ MoveTarget()

virtual void MoreMountains.TopDownEngine.WeaponAim.MoveTarget ( )
protectedvirtual

This method defines how the character's camera target should move

Reimplemented in MoreMountains.TopDownEngine.WeaponAim2D, and MoreMountains.TopDownEngine.WeaponAim3D.

◆ OnDestroy()

void MoreMountains.TopDownEngine.WeaponAim.OnDestroy ( )
protected

On Destroy, we reinstate our cursor if needed

◆ OnDisable()

virtual void MoreMountains.TopDownEngine.WeaponAim.OnDisable ( )
protectedvirtual

On disable we stop listening for events

◆ OnEnable()

virtual void MoreMountains.TopDownEngine.WeaponAim.OnEnable ( )
protectedvirtual

On enable we start listening for events

◆ OnMMEvent()

void MoreMountains.TopDownEngine.WeaponAim.OnMMEvent ( TopDownEngineEvent  engineEvent)

◆ RemoveReticle()

virtual void MoreMountains.TopDownEngine.WeaponAim.RemoveReticle ( )
virtual

Removes any remaining reticle

◆ ResetAdditionalAngle()

virtual void MoreMountains.TopDownEngine.WeaponAim.ResetAdditionalAngle ( )
protectedvirtual

Resets the additional angle

◆ RotateWeapon()

virtual void MoreMountains.TopDownEngine.WeaponAim.RotateWeapon ( Quaternion  newRotation,
bool  forceInstant = false 
)
protectedvirtual

Rotates the weapon, optionnally applying a lerp to it.

Parameters
newRotationNew rotation.

◆ SetCurrentAim()

virtual void MoreMountains.TopDownEngine.WeaponAim.SetCurrentAim ( Vector3  newAim,
bool  setAimAsLastNonNullMovement = false 
)
virtual

Aims the weapon towards a new point

Parameters
newAimNew aim.

Reimplemented in MoreMountains.TopDownEngine.WeaponAim3D, and MoreMountains.TopDownEngine.WeaponAim2D.

◆ Start()

virtual void MoreMountains.TopDownEngine.WeaponAim.Start ( )
protectedvirtual

On Start(), we trigger the initialization

◆ Update()

virtual void MoreMountains.TopDownEngine.WeaponAim.Update ( )
protectedvirtual

Every frame, we compute the aim direction and rotate the weapon accordingly

Reimplemented in MoreMountains.TopDownEngine.WeaponAim2D, and MoreMountains.TopDownEngine.WeaponAim3D.

Member Data Documentation

◆ _additionalAngle

float MoreMountains.TopDownEngine.WeaponAim._additionalAngle
protected

◆ _aimAtDirection

Vector3 MoreMountains.TopDownEngine.WeaponAim._aimAtDirection
protected

◆ _aimAtQuaternion

Quaternion MoreMountains.TopDownEngine.WeaponAim._aimAtQuaternion
protected

◆ _currentAim

Vector3 MoreMountains.TopDownEngine.WeaponAim._currentAim = Vector3.zero
protected

◆ _currentAimAbsolute

Vector3 MoreMountains.TopDownEngine.WeaponAim._currentAimAbsolute = Vector3.zero
protected

◆ _direction

Vector3 MoreMountains.TopDownEngine.WeaponAim._direction
protected

◆ _initialized

bool MoreMountains.TopDownEngine.WeaponAim._initialized = false
protected

◆ _initialRotation

Quaternion MoreMountains.TopDownEngine.WeaponAim._initialRotation
protected

◆ _lastMousePosition

Vector3 MoreMountains.TopDownEngine.WeaponAim._lastMousePosition
protected

◆ _lastNonNullMovement

Vector2 MoreMountains.TopDownEngine.WeaponAim._lastNonNullMovement
protected

◆ _lookRotation

Quaternion MoreMountains.TopDownEngine.WeaponAim._lookRotation
protected

◆ _mainCamera

Camera MoreMountains.TopDownEngine.WeaponAim._mainCamera
protected

◆ _mousePosition

Vector3 MoreMountains.TopDownEngine.WeaponAim._mousePosition
protected

◆ _newCamTargetDirection

Vector3 MoreMountains.TopDownEngine.WeaponAim._newCamTargetDirection
protected

◆ _newCamTargetPosition

Vector3 MoreMountains.TopDownEngine.WeaponAim._newCamTargetPosition
protected

◆ _playerPlane

Plane MoreMountains.TopDownEngine.WeaponAim._playerPlane
protected

◆ _possibleAngleValues

float [] MoreMountains.TopDownEngine.WeaponAim._possibleAngleValues
protected

◆ _reticle

GameObject MoreMountains.TopDownEngine.WeaponAim._reticle
protected

◆ _reticlePosition

Vector3 MoreMountains.TopDownEngine.WeaponAim._reticlePosition
protected

◆ _weapon

Weapon MoreMountains.TopDownEngine.WeaponAim._weapon
protected

◆ AimControl

AimControls MoreMountains.TopDownEngine.WeaponAim.AimControl = AimControls.SecondaryMovement

the aim control mode

◆ AimControlActive

bool MoreMountains.TopDownEngine.WeaponAim.AimControlActive = true

if this is true, this script will be able to read input from its specified AimControl mode

◆ CameraTargetMaxDistance

float MoreMountains.TopDownEngine.WeaponAim.CameraTargetMaxDistance = 10f

the maximum distance at which to move the camera target

◆ CameraTargetOffset

float MoreMountains.TopDownEngine.WeaponAim.CameraTargetOffset = 0.3f

the offset to apply to the camera target along the transform / reticle line

◆ CameraTargetSpeed

float MoreMountains.TopDownEngine.WeaponAim.CameraTargetSpeed = 5f

the speed at which the camera target should be moved

◆ DisplayReticle

bool MoreMountains.TopDownEngine.WeaponAim.DisplayReticle = true

if set to false, the reticle won't be added and displayed

◆ MaximumAngle

float MoreMountains.TopDownEngine.WeaponAim.MaximumAngle = 180f

the maximum angle at which the weapon's rotation will be clamped

◆ MinimumAngle

float MoreMountains.TopDownEngine.WeaponAim.MinimumAngle = -180f

the minimum angle at which the weapon's rotation will be clamped

◆ MinimumMagnitude

float MoreMountains.TopDownEngine.WeaponAim.MinimumMagnitude = 0.2f

the minimum threshold at which the weapon's rotation magnitude will be considered

◆ MouseDeadZoneRadius

float MoreMountains.TopDownEngine.WeaponAim.MouseDeadZoneRadius = 0.5f

the radius around the weapon rotation centre where the mouse will be ignored, to avoid glitches

◆ MoveCameraTargetTowardsReticle

bool MoreMountains.TopDownEngine.WeaponAim.MoveCameraTargetTowardsReticle = false

whether the camera target should be moved towards the reticle to provide a better vision of the possible target. If you don't have a reticle, it'll be moved towards your aim direction.

◆ ReplaceMousePointer

bool MoreMountains.TopDownEngine.WeaponAim.ReplaceMousePointer = true

if set to true, the reticle will replace the mouse pointer

◆ Reticle

GameObject MoreMountains.TopDownEngine.WeaponAim.Reticle

the gameobject to display as the aim's reticle/crosshair. Leave it blank if you don't want a reticle

◆ ReticleAtMousePosition

bool MoreMountains.TopDownEngine.WeaponAim.ReticleAtMousePosition

if set to true, the reticle will be placed at the mouse's position (like a pointer)

◆ ReticleDistance

float MoreMountains.TopDownEngine.WeaponAim.ReticleDistance

the distance at which the reticle will be from the weapon

◆ ReticleHeight

float MoreMountains.TopDownEngine.WeaponAim.ReticleHeight

the height at which the reticle should position itself above the ground, when in Scene mode

◆ ReticleType

ReticleTypes MoreMountains.TopDownEngine.WeaponAim.ReticleType = ReticleTypes.None

Defines whether the reticle is placed in the scene or in the UI.

◆ RotateReticle

bool MoreMountains.TopDownEngine.WeaponAim.RotateReticle = false

if set to true, the reticle will rotate on itself to reflect the weapon's rotation. If not it'll remain stable.

◆ RotationMode

RotationModes MoreMountains.TopDownEngine.WeaponAim.RotationMode = RotationModes.Free

the rotation mode

◆ TargetWeapon

virtual Weapon MoreMountains.TopDownEngine.WeaponAim.TargetWeapon => _weapon

◆ WeaponRotationSpeed

float MoreMountains.TopDownEngine.WeaponAim.WeaponRotationSpeed = 1f

the the speed at which the weapon reaches its new position. Set it to zero if you want movement to directly follow input

Property Documentation

◆ CurrentAim

virtual Vector3 MoreMountains.TopDownEngine.WeaponAim.CurrentAim
get

the weapon's current direction

◆ CurrentAimAbsolute

virtual Vector3 MoreMountains.TopDownEngine.WeaponAim.CurrentAimAbsolute
get

the weapon's current direction, absolute (flip independent)

◆ CurrentAngle

virtual float MoreMountains.TopDownEngine.WeaponAim.CurrentAngle
getprotected set

the current angle the weapon is aiming at

◆ CurrentAngleAbsolute

virtual float MoreMountains.TopDownEngine.WeaponAim.CurrentAngleAbsolute
getprotected set

◆ CurrentAngleRelative

virtual float MoreMountains.TopDownEngine.WeaponAim.CurrentAngleRelative
get

the current angle the weapon is aiming at, adjusted to compensate for the current orientation of the character

◆ CurrentRotation

virtual Quaternion MoreMountains.TopDownEngine.WeaponAim.CurrentRotation
get

the weapon's current rotation


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