Gameplay Guide
This article explains the usage ideas in common gameplay within the generic movement system. GMS includes several concise APIs that can help you quickly integrate with your gameplay logic.
Switching Movement Sets
You can design several different movement sets in your movement definitions, and change the character's control logic and animations by switching movement sets during gameplay.
GMS has built-in several common movement sets that cover basic character control needs. For traditional action/shooting games, you can:
- Default: Used when the character is standing.
- ADS: Used when the character is standing and holding the aim input.
- ADS_Crouched: Used when the character is crouching and holding the aim input.
- Guard: Used when the character is standing and equipped with a melee weapon while holding the defense input.
- Guard_Crouched: Used when the character is crouching and equipped with a melee weapon while holding the defense input.
Each movement set uses different movement controls and animations. When you equip different weapons, you only need to replace different movement definitions (with the same movement set tags but different movement set settings), and the upper logic does not need to change, allowing you to switch control settings and animation settings.
In programming terms: use movement set tags combined with different movement definitions to achieve polymorphism.
Analogous Examples
When you develop new movement modes, you can design new movement sets:
- Riding: You can design MovementSet.Riding and MovementSet.Riding_Aim, corresponding to the control logic and animations when the character is riding and when the character is aiming while riding.
- Climbing: You can design MovementSet.Climb and MovementSet.Climb_Aim, corresponding to the control logic and animations when the character is climbing and when aiming while climbing.
Associated Movement Definitions
In the demo, the character only uses simple key inputs to switch between different movement definitions. In real game development, you usually need to work with other systems.
Taking the weapon system as an example:
In the settings of each weapon, there should be a movement definition field to associate the weapon with its corresponding movement definition.
When the weapon is equipped, switch the current movement definition of the movement system component to the movement definition associated with the weapon.
For more complex situations, such as distinguishing between male and female characters, you can also add similar Male_MovementDefinition or Female_MovementDefinition to the weapon, and select the most suitable movement definition based on the character's gender when the weapon is activated.
Switching Movement States
Movement states refer to states such as walking, running, sprinting, etc.
Call SetDesiredMovement on the component to request walking, running, or sprinting. The Character path applies control parameters for the requested state. During a transition, the current MovementState is classified from actual speed to reflect the state the character has reached.
AI desired-speed classification and actual-speed classification use the Control Setting's speed rule. For a temporary boost, slowdown, or catch-up, call SetRuntimeSpeedAdjustment; call ClearRuntimeSpeedAdjustment when the effect ends to restore the active setting's base speed. See Movement Control Settings.
In multiplayer, RuntimeSpeedAdjustment is transient and is not automatically replicated. Apply it through authoritative gameplay logic. If client prediction needs the adjustment, mirror it locally in your project and test its removal as well.
Switching Rotation Modes
Call SetDesiredRotationMode to request a rotation mode. For example, use ViewDirection while aiming and return to VelocityDirection when aiming ends. The current Movement State's allowed rotation modes can restrict the request; see Movement Control Settings.
For example, in a combat system: if you lock onto a target, the rotation mode should switch to ViewMode; if you unlock a target, it should switch to VelocityMode.
For example, with ranged weapons: when you hold the right mouse button, your rotation mode should be set to ViewMode.
Character Orientation Control
GMS has its own rotation system, and the way the character rotates will depend on the different rotation modes, using different rotation settings in the movement control settings.
The current rotation mode and its settings determine facing. VelocityDirection can follow velocity or movement input, while ViewDirection generally follows the view. Grounded, in-air, and rotation policy settings also affect the result.
For more information, please refer to Movement Control Settings.
AI Orientation Control
When you want to manually control the orientation of AI characters, you should set the character's rotation mode to ViewDirection and update the direction the character should face by setting ControlRotation.
You can also call the APIs starting with SetRotation on the GMS_CharacterMovementSystem component to directly control the character's rotation.
Switching Overlay Modes
Responding to Events
When you call different functions on the movement system component, corresponding events will be triggered, allowing you to respond to the results of the operations.
For example: when you switch from the aiming movement set (causing the character to enter walking state) back to the default movement set, you want the character to return to the jogging state. You can perform the following operations:
Other Available APIs
In GMS, all commonly used APIs are categorized with GMS as the prefix. You can type GMS in the ContextAction list in Blueprints to see all available APIs.