TopDown Engine  v3.6
MoreMountains.TopDownEngine.WeaponAim3D Class Reference

Add this component to a Weapon and you'll be able to aim it (meaning you'll rotate it) Supported control modes are mouse, primary movement (you aim wherever you direct your character) and secondary movement (using a secondary axis, separate from the movement). More...

Inheritance diagram for MoreMountains.TopDownEngine.WeaponAim3D:
MoreMountains.TopDownEngine.WeaponAim MoreMountains.TopDownEngine.TopDownMonoBehaviour MoreMountains.Tools.MMEventListener< TopDownEngineEvent > MoreMountains.Tools.MMMonoBehaviour

Public Types

enum  AimCenters { AimCenters.Owner, AimCenters.Weapon }
 
- Public Types inherited from MoreMountains.TopDownEngine.WeaponAim
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 GetOffAim ()
 
virtual void GetPrimaryMovementAim ()
 
virtual void GetSecondaryMovementAim ()
 
virtual void GetScriptAim ()
 
virtual void GetMouseAim ()
 
override void SetCurrentAim (Vector3 newAim, bool setAimAsLastNonNullMovement=false)
 Aims the weapon towards a new point More...
 
- Public Member Functions inherited from MoreMountains.TopDownEngine.WeaponAim
virtual void ApplyAim ()
 
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

bool Unrestricted3DAim = false
 if this is true, aim will be unrestricted to angles, and will aim freely in all 3 axis, useful when dealing with AI and elevation More...
 
AimCenters AimCenter = AimCenters.Owner
 whether aim direction should be computed from the owner, or from the weapon More...
 
bool ReticleMovesWithSlopes = false
 whether or not the reticle should move vertically to stay above slopes More...
 
LayerMask ReticleObstacleMask = LayerManager.ObstaclesLayerMask
 the layers the reticle should consider as obstacles to move on More...
 
float MaximumSlopeElevation = 50f
 the maximum slope elevation for the reticle More...
 
bool AvoidNullAim = true
 if this is true, the aim system will try to compensate when aim direction is null (for example when you haven't set any primary input yet) More...
 
- Public Attributes inherited from MoreMountains.TopDownEngine.WeaponAim
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

override void Initialization ()
 Grabs the weapon component, initializes the angle values More...
 
virtual void Reset ()
 
override void GetCurrentAim ()
 Computes the current aim direction More...
 
override void Update ()
 Every frame, we compute the aim direction and rotate the weapon accordingly More...
 
virtual void FixedUpdate ()
 At fixed update we move the target and reticle More...
 
virtual void UpdatePlane ()
 
override void DetermineWeaponRotation ()
 Determines the weapon rotation based on the current aim direction More...
 
override void AimAt (Vector3 target)
 
override void InitializeReticle ()
 Initializes the reticle based on the settings defined in the inspector More...
 
override void MoveReticle ()
 Every frame, moves the reticle if it's been told to follow the pointer More...
 
override void MoveTarget ()
 This method defines how the character's camera target should move More...
 
- Protected Member Functions inherited from MoreMountains.TopDownEngine.WeaponAim
virtual void Start ()
 On Start(), we trigger the initialization More...
 
virtual void LateUpdate ()
 On LateUpdate, resets any additional angle More...
 
virtual void RotateWeapon (Quaternion newRotation, bool forceInstant=false)
 Rotates the weapon, optionnally applying a lerp to it. 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

Vector2 _inputMovement
 
Vector3 _slopeTargetPosition
 
Vector3 _weaponAimCurrentAim
 
- Protected Attributes inherited from MoreMountains.TopDownEngine.WeaponAim
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
 

Additional Inherited Members

- Properties inherited from MoreMountains.TopDownEngine.WeaponAim
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...
 

Detailed Description

Add this component to a Weapon and you'll be able to aim it (meaning you'll rotate it) Supported control modes are mouse, primary movement (you aim wherever you direct your character) and secondary movement (using a secondary axis, separate from the movement).

Member Enumeration Documentation

◆ AimCenters

Enumerator
Owner 
Weapon 

Member Function Documentation

◆ AimAt()

override void MoreMountains.TopDownEngine.WeaponAim3D.AimAt ( Vector3  target)
protectedvirtual

◆ DetermineWeaponRotation()

override void MoreMountains.TopDownEngine.WeaponAim3D.DetermineWeaponRotation ( )
protectedvirtual

Determines the weapon rotation based on the current aim direction

Reimplemented from MoreMountains.TopDownEngine.WeaponAim.

◆ FixedUpdate()

virtual void MoreMountains.TopDownEngine.WeaponAim3D.FixedUpdate ( )
protectedvirtual

At fixed update we move the target and reticle

◆ GetCurrentAim()

override void MoreMountains.TopDownEngine.WeaponAim3D.GetCurrentAim ( )
protectedvirtual

Computes the current aim direction

Reimplemented from MoreMountains.TopDownEngine.WeaponAim.

◆ GetMouseAim()

virtual void MoreMountains.TopDownEngine.WeaponAim3D.GetMouseAim ( )
virtual

◆ GetOffAim()

virtual void MoreMountains.TopDownEngine.WeaponAim3D.GetOffAim ( )
virtual

◆ GetPrimaryMovementAim()

virtual void MoreMountains.TopDownEngine.WeaponAim3D.GetPrimaryMovementAim ( )
virtual

◆ GetScriptAim()

virtual void MoreMountains.TopDownEngine.WeaponAim3D.GetScriptAim ( )
virtual

◆ GetSecondaryMovementAim()

virtual void MoreMountains.TopDownEngine.WeaponAim3D.GetSecondaryMovementAim ( )
virtual

◆ Initialization()

override void MoreMountains.TopDownEngine.WeaponAim3D.Initialization ( )
protectedvirtual

Grabs the weapon component, initializes the angle values

Reimplemented from MoreMountains.TopDownEngine.WeaponAim.

◆ InitializeReticle()

override void MoreMountains.TopDownEngine.WeaponAim3D.InitializeReticle ( )
protectedvirtual

Initializes the reticle based on the settings defined in the inspector

Reimplemented from MoreMountains.TopDownEngine.WeaponAim.

◆ MoveReticle()

override void MoreMountains.TopDownEngine.WeaponAim3D.MoveReticle ( )
protectedvirtual

Every frame, moves the reticle if it's been told to follow the pointer

Reimplemented from MoreMountains.TopDownEngine.WeaponAim.

◆ MoveTarget()

override void MoreMountains.TopDownEngine.WeaponAim3D.MoveTarget ( )
protectedvirtual

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

Reimplemented from MoreMountains.TopDownEngine.WeaponAim.

◆ Reset()

virtual void MoreMountains.TopDownEngine.WeaponAim3D.Reset ( )
protectedvirtual

◆ SetCurrentAim()

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

Aims the weapon towards a new point

Parameters
newAimNew aim.

Reimplemented from MoreMountains.TopDownEngine.WeaponAim.

◆ Update()

override void MoreMountains.TopDownEngine.WeaponAim3D.Update ( )
protectedvirtual

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

Reimplemented from MoreMountains.TopDownEngine.WeaponAim.

◆ UpdatePlane()

virtual void MoreMountains.TopDownEngine.WeaponAim3D.UpdatePlane ( )
protectedvirtual

Member Data Documentation

◆ _inputMovement

Vector2 MoreMountains.TopDownEngine.WeaponAim3D._inputMovement
protected

◆ _slopeTargetPosition

Vector3 MoreMountains.TopDownEngine.WeaponAim3D._slopeTargetPosition
protected

◆ _weaponAimCurrentAim

Vector3 MoreMountains.TopDownEngine.WeaponAim3D._weaponAimCurrentAim
protected

◆ AimCenter

AimCenters MoreMountains.TopDownEngine.WeaponAim3D.AimCenter = AimCenters.Owner

whether aim direction should be computed from the owner, or from the weapon

◆ AvoidNullAim

bool MoreMountains.TopDownEngine.WeaponAim3D.AvoidNullAim = true

if this is true, the aim system will try to compensate when aim direction is null (for example when you haven't set any primary input yet)

◆ MaximumSlopeElevation

float MoreMountains.TopDownEngine.WeaponAim3D.MaximumSlopeElevation = 50f

the maximum slope elevation for the reticle

◆ ReticleMovesWithSlopes

bool MoreMountains.TopDownEngine.WeaponAim3D.ReticleMovesWithSlopes = false

whether or not the reticle should move vertically to stay above slopes

◆ ReticleObstacleMask

LayerMask MoreMountains.TopDownEngine.WeaponAim3D.ReticleObstacleMask = LayerManager.ObstaclesLayerMask

the layers the reticle should consider as obstacles to move on

◆ Unrestricted3DAim

bool MoreMountains.TopDownEngine.WeaponAim3D.Unrestricted3DAim = false

if this is true, aim will be unrestricted to angles, and will aim freely in all 3 axis, useful when dealing with AI and elevation


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