Player Movement
The PlayerMovement
is responsible for handling the movement mechanics of a player character. Player movement manages the player's velocity, movement, and the transition between different movement states such as walking or running.
Properties
private PlayerWorker playerWorker
: References thePlayerWorker
associated withPlayerMovement
private Vector3 velocity
: Represents the current velocity of the player in the 3D space.private Vector3 normalVector
: Represents the normal vector to the plane on which the player is moving.private float speed = 2f
: Represents the speed at which the player moves.public bool isMoving
: Represents whether the player is currently moving.
Constructor
public PlayerMovement(PlayerWorker playerWorker)
: Initializes a new instance of thePlayerMovement
class, assigning thePlayerWorker
.
Methods
public void OnUpdate()
: Updates the player's movement each frame.public void SetMovementPosition(Vector2 position)
: Sets the player's movement direction based on the input position. The input is a 2D vector, which is then converted and projected onto the movement plane defined bynormalVector
.public void Move()
: Handles the actual movement of the player. It checks if the player should move (based on velocity), moves the player's position, manages the transition of movement-related animations (like running), and applies friction to simulate a natural slow-down of movement.public void ApplyFriction()
: Reduces the player's velocity gradually to simulate friction.
Last updated