-
Notifications
You must be signed in to change notification settings - Fork 14
Locomotion
This section will provide you with an overview of how the Locomotion works.
The current implementation of Locomotion is based on Unity's CharacterController component and Unity's Animation Rigging package for Inverse Kinematics.
All the Locomotion and IK settings are centralized at the CharacterControllerSettings scriptable object.
The Locomotion is being initialized at CharacterMotionPlugin
All the systems are composed of running and jumping can be found at:
CalculateCharacterVelocitySystemInterpolateCharacterSystemRotateCharacterSystemCharacterAnimationSystem
This system is the one that decides where the Avatar is moving toward, it uses these static classes in this particular order:
This class uses the MovementInputComponent to determine the movement direction.
It also calculates the current velocity based on multiple acceleration settings, based on the grounded flag.
This class also increases/decreases the velocity based on the current slope angle.
This class detects if the Avatar is on a steep slope, making the avatar slide.
To detect the current slope we do a SphereCast downwards from the character's center.
This class detects if the Avatar is moving toward a Wall, reducing its movement based on the normal direction of the wall.
To detect the wall we are bumping into we use a SphereCast based on the current movement direction, from our character's center.
This could be further improved by using a CapsuleCast.
This class uses the JumpInputComponent to apply a vertical velocity for the Avatar to jump properly.
To detect if a Player can jump properly we use the Physics Ticks to time when we can jump based on when the jump button was pressed.
This class also implements 2 Coyote Timer mechanics:
- Pressing jump before touching the ground: We give the jump input some bonus frames so if we are grounded after we press the jump button, we take that as a valid action.
- Pressing Jump late after starting to fall: Same as above but when you jump when not grounded.
This class uses multiple CharacterRigidTransform flags to decide how we apply gravity to the Avatar.
If the player is grounded the gravity is reset.
If the player is on a steep slope we first convert the current gravity to the slope gravity to maintain momentum when falling into a steep slope.
If the player keeps pressing the jump button after jumping, we reduce the current gravity to make the jump higher
If the current vertical velocity is positive we multiply the gravity by a factor to reduce the floatiness feel and to make the jump faster and more responsive, this gravity multiplier is also used at ApplyJump
This class applies Drag to the current velocity to slow down the Avatar when jumping and moving forward to reduce how far the player can get while jumping.
This class uses the current Avatar velocity to decide the current Avatar's forward direction. We also detect whether the Avatar is on a Steep Slope to change the direction towards the slide direction.
TBD
TBD
TBD