using UnityEngine;
namespace Cyber.Entities {
///
/// A syncable component that all characters have. Controls the character's subsystems.
///
public class Character : SyncBase {
///
/// How fast the player should move in Unity's spatial units per second.
///
public float MovementSpeed = 5.0f;
///
/// The character controller, used to move the character. Handles collisions.
///
public CharacterController CharacterController;
private Vector3 MovementDirection = new Vector3();
///
/// Moves the character in the given direction.
///
/// Movement direction.
public void Move(Vector3 Direction) {
if (!Direction.Equals(MovementDirection)) {
MovementDirection = Direction.normalized;
}
}
///
/// Stops the player from moving.
///
public void Stop() {
if (Moving()) {
MovementDirection = new Vector3();
}
}
///
/// Whether the player is moving or not.
///
public bool Moving() {
return MovementDirection.sqrMagnitude != 0;
}
private void FixedUpdate() {
CharacterController.Move(MovementDirection * MovementSpeed * Time.fixedDeltaTime);
}
}
}