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

Add this ability to a Character to have it handle ground movement (walk, and potentially run, crawl, etc) in x and z direction for 3D, x and y for 2D Animator parameters : Speed (float), Walking (bool) More...

Inheritance diagram for MoreMountains.TopDownEngine.CharacterMovement:
MoreMountains.TopDownEngine.CharacterAbility MoreMountains.TopDownEngine.TopDownMonoBehaviour MoreMountains.Tools.MMMonoBehaviour

Public Types

enum  Movements {
  Movements.Free, Movements.Strict2DirectionsHorizontal, Movements.Strict2DirectionsVertical, Movements.Strict4Directions,
  Movements.Strict8Directions
}
 the possible rotation modes for the character More...
 

Public Member Functions

override void ResetAbility ()
 Resets character movement states and speeds More...
 
override void ProcessAbility ()
 The second of the 3 passes you can have in your ability. Think of it as Update() More...
 
virtual void SetMovement (Vector2 value)
 Sets the horizontal move value. More...
 
virtual void SetHorizontalMovement (float value)
 Sets the horizontal part of the movement More...
 
virtual void SetVerticalMovement (float value)
 Sets the vertical part of the movement More...
 
virtual void ApplyMovementMultiplier (float movementMultiplier, float duration)
 Applies a movement multiplier for the specified duration More...
 
virtual void SetContextSpeedMultiplier (float newMovementSpeedMultiplier)
 Stacks a new context speed multiplier More...
 
virtual void ResetContextSpeedMultiplier ()
 Revers the context speed multiplier to its previous value More...
 
virtual void ResetSpeed ()
 Resets this character's speed More...
 
override void UpdateAnimator ()
 Sends the current speed and the current value of the Walking state to the animator More...
 
- Public Member Functions inherited from MoreMountains.TopDownEngine.CharacterAbility
delegate void AbilityEvent ()
 
virtual string HelpBoxText ()
 This method is only used to display a helpbox text at the beginning of the ability's inspector. More...
 
virtual void ForceInitialization ()
 Call this any time you want to force this ability to initialize (again) More...
 
virtual void ResetInput ()
 Resets all input for this ability. Can be overridden for ability specific directives More...
 
virtual void EarlyProcessAbility ()
 The first of the 3 passes you can have in your ability. Think of it as EarlyUpdate() if it existed More...
 
virtual void LateProcessAbility ()
 The last of the 3 passes you can have in your ability. Think of it as LateUpdate() More...
 
virtual void PermitAbility (bool abilityPermitted)
 Changes the status of the ability's permission More...
 
virtual void Flip ()
 Override this to specify what should happen in this ability when the character flips More...
 
virtual void SetInputManager (InputManager newInputManager)
 Changes the reference to the input manager with the one set in parameters More...
 
virtual void PlayAbilityStartSfx ()
 Plays the ability start sound effect More...
 
virtual void PlayAbilityUsedSfx ()
 Plays the ability used sound effect More...
 
virtual void StopAbilityUsedSfx ()
 Stops the ability used sound effect More...
 
virtual void PlayAbilityStopSfx ()
 Plays the ability stop sound effect More...
 
virtual void PlayAbilityStartFeedbacks ()
 Plays the ability start sound effect More...
 
virtual void StopStartFeedbacks ()
 Stops the ability used sound effect More...
 
virtual void PlayAbilityStopFeedbacks ()
 Plays the ability stop sound effect More...
 

Public Attributes

Movements Movement = Movements.Free
 whether the character can move freely, in 2D only, in 4 or 8 cardinal directions More...
 
bool InputAuthorized = true
 whether or not movement input is authorized at that time More...
 
bool AnalogInput = false
 whether or not input should be analog More...
 
bool ScriptDrivenInput = false
 whether or not input should be set from another script More...
 
float WalkSpeed = 6f
 the speed of the character when it's walking More...
 
bool ShouldSetMovement = true
 whether or not this component should set the controller's movement More...
 
float IdleThreshold = 0.05f
 the speed threshold after which the character is not considered idle anymore More...
 
float Acceleration = 10f
 the acceleration to apply to the current speed / 0f : no acceleration, instant full speed More...
 
float Deceleration = 10f
 the deceleration to apply to the current speed / 0f : no deceleration, instant stop More...
 
bool InterpolateMovementSpeed = false
 whether or not to interpolate movement speed More...
 
Stack< float > ContextSpeedStack = new Stack<float>()
 the multiplier to apply to the horizontal movement, applied by contextual elements (movement zones, etc) More...
 
virtual float ContextSpeedMultiplier => ContextSpeedStack.Count > 0 ? ContextSpeedStack.Peek() : 1
 
ParticleSystem[] WalkParticles
 the particles to trigger while walking More...
 
ParticleSystem[] TouchTheGroundParticles
 the particles to trigger when touching the ground More...
 
AudioClip[] TouchTheGroundSfx
 the sfx to trigger when touching the ground More...
 
- Public Attributes inherited from MoreMountains.TopDownEngine.CharacterAbility
AudioClip AbilityStartSfx
 the sound fx to play when the ability starts More...
 
AudioClip AbilityInProgressSfx
 the sound fx to play while the ability is running More...
 
AudioClip AbilityStopSfx
 the sound fx to play when the ability stops More...
 
MMFeedbacks AbilityStartFeedbacks
 the feedbacks to play when the ability starts More...
 
MMFeedbacks AbilityStopFeedbacks
 the feedbacks to play when the ability stops More...
 
bool AbilityPermitted = true
 if true, this ability can perform as usual, if not, it'll be ignored. You can use this to unlock abilities over time for example More...
 
CharacterStates.MovementStates[] BlockingMovementStates
 an array containing all the blocking movement states. If the Character is in one of these states and tries to trigger this ability, it won't be permitted. Useful to prevent this ability from being used while Idle or Swimming, for example. More...
 
CharacterStates.CharacterConditions[] BlockingConditionStates
 an array containing all the blocking condition states. If the Character is in one of these states and tries to trigger this ability, it won't be permitted. Useful to prevent this ability from being used while dead, for example. More...
 
Weapon.WeaponStates[] BlockingWeaponStates
 an array containing all the blocking weapon states. If one of the character's weapons is in one of these states and yet the character tries to trigger this ability, it won't be permitted. Useful to prevent this ability from being used while attacking, for example. More...
 
AbilityEvent OnAbilityStart
 
AbilityEvent OnAbilityStop
 

Protected Member Functions

override void Initialization ()
 On Initialization, we set our movement speed to WalkSpeed. More...
 
override void HandleInput ()
 Called at the very start of the ability's cycle, and intended to be overridden, looks for input and calls methods if conditions are met More...
 
virtual IEnumerator ApplyMovementMultiplierCo (float movementMultiplier, float duration)
 A coroutine used to apply a movement multiplier for a certain duration only More...
 
virtual void HandleDirection ()
 Modifies player input to account for the selected movement mode More...
 
virtual void HandleMovement ()
 Called at Update(), handles horizontal movement More...
 
virtual void HandleFrozen ()
 Describes what happens when the character is in the frozen state More...
 
virtual void SetMovement ()
 Moves the controller More...
 
virtual void CheckJustGotGrounded ()
 Every frame, checks if we just hit the ground, and if yes, changes the state and triggers a particle effect More...
 
virtual void Feedbacks ()
 Plays particles when walking, and particles and sounds when landing More...
 
override void OnRespawn ()
 On Respawn, resets the speed More...
 
override void OnDeath ()
 Override this to describe what should happen to this ability when the character respawns More...
 
virtual void DisableWalkParticles ()
 Disables all walk particle systems that may be playing More...
 
override void OnDisable ()
 On disable we make sure to turn off anything that could still be playing More...
 
override void InitializeAnimatorParameters ()
 Adds required animator parameters to the animator parameters list if they exist More...
 
- Protected Member Functions inherited from MoreMountains.TopDownEngine.CharacterAbility
virtual void Awake ()
 On awake we proceed to pre initializing our ability More...
 
virtual void Start ()
 On Start(), we call the ability's intialization More...
 
virtual void PreInitialization ()
 A method you can override to have an initialization before the actual initialization More...
 
virtual void BindAnimator ()
 Binds the animator from the character and initializes the animator parameters More...
 
virtual void InternalHandleInput ()
 Internal method to check if an input manager is present or not More...
 
virtual void RegisterAnimatorParameter (string parameterName, AnimatorControllerParameterType parameterType, out int parameter)
 Registers a new animator parameter to the list More...
 
virtual void OnHit ()
 Override this to describe what should happen to this ability when the character takes a hit More...
 
virtual void OnEnable ()
 On enable, we bind our respawn delegate More...
 

Protected Attributes

float _movementSpeed
 
float _horizontalMovement
 
float _verticalMovement
 
Vector3 _movementVector
 
Vector2 _currentInput = Vector2.zero
 
Vector2 _normalizedInput
 
Vector2 _lerpedInput = Vector2.zero
 
float _acceleration = 0f
 
bool _walkParticlesPlaying = false
 
int _speedAnimationParameter
 
int _walkingAnimationParameter
 
int _idleAnimationParameter
 
- Protected Attributes inherited from MoreMountains.TopDownEngine.CharacterAbility
Character _character
 
TopDownController _controller
 
TopDownController2D _controller2D
 
TopDownController3D _controller3D
 
GameObject _model
 
Health _health
 
CharacterMovement _characterMovement
 
InputManager _inputManager
 
Animator _animator = null
 
CharacterStates _state
 
SpriteRenderer _spriteRenderer
 
MMStateMachine< CharacterStates.MovementStates_movement
 
MMStateMachine< CharacterStates.CharacterConditions_condition
 
AudioSource _abilityInProgressSfx
 
bool _abilityInitialized = false
 
float _verticalInput
 
float _horizontalInput
 
bool _startFeedbackIsPlaying = false
 
List< CharacterHandleWeapon_handleWeaponList
 

Static Protected Attributes

const string _speedAnimationParameterName = "Speed"
 
const string _walkingAnimationParameterName = "Walking"
 
const string _idleAnimationParameterName = "Idle"
 

Properties

virtual float MovementSpeed [get, set]
 the current reference movement speed More...
 
virtual bool MovementForbidden [get, set]
 if this is true, movement will be forbidden (as well as flip) More...
 
virtual float MovementSpeedMaxMultiplier = float.MaxValue [get, set]
 
float MovementSpeedMultiplier [get, set]
 the multiplier to apply to the horizontal movement More...
 
- Properties inherited from MoreMountains.TopDownEngine.CharacterAbility
virtual bool AbilityAuthorized [get]
 
virtual bool AbilityInitialized [get]
 whether or not this ability has been initialized More...
 

Detailed Description

Add this ability to a Character to have it handle ground movement (walk, and potentially run, crawl, etc) in x and z direction for 3D, x and y for 2D Animator parameters : Speed (float), Walking (bool)

Member Enumeration Documentation

◆ Movements

the possible rotation modes for the character

Enumerator
Free 
Strict2DirectionsHorizontal 
Strict2DirectionsVertical 
Strict4Directions 
Strict8Directions 

Member Function Documentation

◆ ApplyMovementMultiplier()

virtual void MoreMountains.TopDownEngine.CharacterMovement.ApplyMovementMultiplier ( float  movementMultiplier,
float  duration 
)
virtual

Applies a movement multiplier for the specified duration

Parameters
movementMultiplier
duration

◆ ApplyMovementMultiplierCo()

virtual IEnumerator MoreMountains.TopDownEngine.CharacterMovement.ApplyMovementMultiplierCo ( float  movementMultiplier,
float  duration 
)
protectedvirtual

A coroutine used to apply a movement multiplier for a certain duration only

Parameters
movementMultiplier
duration
Returns

◆ CheckJustGotGrounded()

virtual void MoreMountains.TopDownEngine.CharacterMovement.CheckJustGotGrounded ( )
protectedvirtual

Every frame, checks if we just hit the ground, and if yes, changes the state and triggers a particle effect

◆ DisableWalkParticles()

virtual void MoreMountains.TopDownEngine.CharacterMovement.DisableWalkParticles ( )
protectedvirtual

Disables all walk particle systems that may be playing

◆ Feedbacks()

virtual void MoreMountains.TopDownEngine.CharacterMovement.Feedbacks ( )
protectedvirtual

Plays particles when walking, and particles and sounds when landing

◆ HandleDirection()

virtual void MoreMountains.TopDownEngine.CharacterMovement.HandleDirection ( )
protectedvirtual

Modifies player input to account for the selected movement mode

◆ HandleFrozen()

virtual void MoreMountains.TopDownEngine.CharacterMovement.HandleFrozen ( )
protectedvirtual

Describes what happens when the character is in the frozen state

◆ HandleInput()

override void MoreMountains.TopDownEngine.CharacterMovement.HandleInput ( )
protectedvirtual

Called at the very start of the ability's cycle, and intended to be overridden, looks for input and calls methods if conditions are met

Reimplemented from MoreMountains.TopDownEngine.CharacterAbility.

◆ HandleMovement()

virtual void MoreMountains.TopDownEngine.CharacterMovement.HandleMovement ( )
protectedvirtual

Called at Update(), handles horizontal movement

◆ Initialization()

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

On Initialization, we set our movement speed to WalkSpeed.

Reimplemented from MoreMountains.TopDownEngine.CharacterAbility.

◆ InitializeAnimatorParameters()

override void MoreMountains.TopDownEngine.CharacterMovement.InitializeAnimatorParameters ( )
protectedvirtual

Adds required animator parameters to the animator parameters list if they exist

Reimplemented from MoreMountains.TopDownEngine.CharacterAbility.

◆ OnDeath()

override void MoreMountains.TopDownEngine.CharacterMovement.OnDeath ( )
protectedvirtual

Override this to describe what should happen to this ability when the character respawns

Reimplemented from MoreMountains.TopDownEngine.CharacterAbility.

◆ OnDisable()

override void MoreMountains.TopDownEngine.CharacterMovement.OnDisable ( )
protectedvirtual

On disable we make sure to turn off anything that could still be playing

Reimplemented from MoreMountains.TopDownEngine.CharacterAbility.

◆ OnRespawn()

override void MoreMountains.TopDownEngine.CharacterMovement.OnRespawn ( )
protectedvirtual

On Respawn, resets the speed

Reimplemented from MoreMountains.TopDownEngine.CharacterAbility.

◆ ProcessAbility()

override void MoreMountains.TopDownEngine.CharacterMovement.ProcessAbility ( )
virtual

The second of the 3 passes you can have in your ability. Think of it as Update()

Reimplemented from MoreMountains.TopDownEngine.CharacterAbility.

◆ ResetAbility()

override void MoreMountains.TopDownEngine.CharacterMovement.ResetAbility ( )
virtual

Resets character movement states and speeds

Reimplemented from MoreMountains.TopDownEngine.CharacterAbility.

◆ ResetContextSpeedMultiplier()

virtual void MoreMountains.TopDownEngine.CharacterMovement.ResetContextSpeedMultiplier ( )
virtual

Revers the context speed multiplier to its previous value

◆ ResetSpeed()

virtual void MoreMountains.TopDownEngine.CharacterMovement.ResetSpeed ( )
virtual

Resets this character's speed

◆ SetContextSpeedMultiplier()

virtual void MoreMountains.TopDownEngine.CharacterMovement.SetContextSpeedMultiplier ( float  newMovementSpeedMultiplier)
virtual

Stacks a new context speed multiplier

Parameters
newMovementSpeedMultiplier

◆ SetHorizontalMovement()

virtual void MoreMountains.TopDownEngine.CharacterMovement.SetHorizontalMovement ( float  value)
virtual

Sets the horizontal part of the movement

Parameters
value

◆ SetMovement() [1/2]

virtual void MoreMountains.TopDownEngine.CharacterMovement.SetMovement ( )
protectedvirtual

Moves the controller

◆ SetMovement() [2/2]

virtual void MoreMountains.TopDownEngine.CharacterMovement.SetMovement ( Vector2  value)
virtual

Sets the horizontal move value.

Parameters
valueHorizontal move value, between -1 and 1 - positive : will move to the right, negative : will move left

◆ SetVerticalMovement()

virtual void MoreMountains.TopDownEngine.CharacterMovement.SetVerticalMovement ( float  value)
virtual

Sets the vertical part of the movement

Parameters
value

◆ UpdateAnimator()

override void MoreMountains.TopDownEngine.CharacterMovement.UpdateAnimator ( )
virtual

Sends the current speed and the current value of the Walking state to the animator

Reimplemented from MoreMountains.TopDownEngine.CharacterAbility.

Member Data Documentation

◆ _acceleration

float MoreMountains.TopDownEngine.CharacterMovement._acceleration = 0f
protected

◆ _currentInput

Vector2 MoreMountains.TopDownEngine.CharacterMovement._currentInput = Vector2.zero
protected

◆ _horizontalMovement

float MoreMountains.TopDownEngine.CharacterMovement._horizontalMovement
protected

◆ _idleAnimationParameter

int MoreMountains.TopDownEngine.CharacterMovement._idleAnimationParameter
protected

◆ _idleAnimationParameterName

const string MoreMountains.TopDownEngine.CharacterMovement._idleAnimationParameterName = "Idle"
staticprotected

◆ _lerpedInput

Vector2 MoreMountains.TopDownEngine.CharacterMovement._lerpedInput = Vector2.zero
protected

◆ _movementSpeed

float MoreMountains.TopDownEngine.CharacterMovement._movementSpeed
protected

◆ _movementVector

Vector3 MoreMountains.TopDownEngine.CharacterMovement._movementVector
protected

◆ _normalizedInput

Vector2 MoreMountains.TopDownEngine.CharacterMovement._normalizedInput
protected

◆ _speedAnimationParameter

int MoreMountains.TopDownEngine.CharacterMovement._speedAnimationParameter
protected

◆ _speedAnimationParameterName

const string MoreMountains.TopDownEngine.CharacterMovement._speedAnimationParameterName = "Speed"
staticprotected

◆ _verticalMovement

float MoreMountains.TopDownEngine.CharacterMovement._verticalMovement
protected

◆ _walkingAnimationParameter

int MoreMountains.TopDownEngine.CharacterMovement._walkingAnimationParameter
protected

◆ _walkingAnimationParameterName

const string MoreMountains.TopDownEngine.CharacterMovement._walkingAnimationParameterName = "Walking"
staticprotected

◆ _walkParticlesPlaying

bool MoreMountains.TopDownEngine.CharacterMovement._walkParticlesPlaying = false
protected

◆ Acceleration

float MoreMountains.TopDownEngine.CharacterMovement.Acceleration = 10f

the acceleration to apply to the current speed / 0f : no acceleration, instant full speed

◆ AnalogInput

bool MoreMountains.TopDownEngine.CharacterMovement.AnalogInput = false

whether or not input should be analog

◆ ContextSpeedMultiplier

virtual float MoreMountains.TopDownEngine.CharacterMovement.ContextSpeedMultiplier => ContextSpeedStack.Count > 0 ? ContextSpeedStack.Peek() : 1

◆ ContextSpeedStack

Stack<float> MoreMountains.TopDownEngine.CharacterMovement.ContextSpeedStack = new Stack<float>()

the multiplier to apply to the horizontal movement, applied by contextual elements (movement zones, etc)

◆ Deceleration

float MoreMountains.TopDownEngine.CharacterMovement.Deceleration = 10f

the deceleration to apply to the current speed / 0f : no deceleration, instant stop

◆ IdleThreshold

float MoreMountains.TopDownEngine.CharacterMovement.IdleThreshold = 0.05f

the speed threshold after which the character is not considered idle anymore

◆ InputAuthorized

bool MoreMountains.TopDownEngine.CharacterMovement.InputAuthorized = true

whether or not movement input is authorized at that time

◆ InterpolateMovementSpeed

bool MoreMountains.TopDownEngine.CharacterMovement.InterpolateMovementSpeed = false

whether or not to interpolate movement speed

◆ Movement

Movements MoreMountains.TopDownEngine.CharacterMovement.Movement = Movements.Free

whether the character can move freely, in 2D only, in 4 or 8 cardinal directions

◆ ScriptDrivenInput

bool MoreMountains.TopDownEngine.CharacterMovement.ScriptDrivenInput = false

whether or not input should be set from another script

◆ ShouldSetMovement

bool MoreMountains.TopDownEngine.CharacterMovement.ShouldSetMovement = true

whether or not this component should set the controller's movement

◆ TouchTheGroundParticles

ParticleSystem [] MoreMountains.TopDownEngine.CharacterMovement.TouchTheGroundParticles

the particles to trigger when touching the ground

◆ TouchTheGroundSfx

AudioClip [] MoreMountains.TopDownEngine.CharacterMovement.TouchTheGroundSfx

the sfx to trigger when touching the ground

◆ WalkParticles

ParticleSystem [] MoreMountains.TopDownEngine.CharacterMovement.WalkParticles

the particles to trigger while walking

◆ WalkSpeed

float MoreMountains.TopDownEngine.CharacterMovement.WalkSpeed = 6f

the speed of the character when it's walking

Property Documentation

◆ MovementForbidden

virtual bool MoreMountains.TopDownEngine.CharacterMovement.MovementForbidden
getset

if this is true, movement will be forbidden (as well as flip)

◆ MovementSpeed

virtual float MoreMountains.TopDownEngine.CharacterMovement.MovementSpeed
getset

the current reference movement speed

◆ MovementSpeedMaxMultiplier

virtual float MoreMountains.TopDownEngine.CharacterMovement.MovementSpeedMaxMultiplier = float.MaxValue
getset

◆ MovementSpeedMultiplier

float MoreMountains.TopDownEngine.CharacterMovement.MovementSpeedMultiplier
getset

the multiplier to apply to the horizontal movement


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