Ejemplo n.º 1
0
    public void UpdatePlayerMovement(PlayerObjectState playerObjectState)
    {
        var playerObjectComponent = FindPlayerObjectComponent(playerObjectState.Id);

        if (playerObjectComponent == null)
        {
            return;
        }

        ApplyLookDirAnglesToPlayer(playerObjectComponent, playerObjectState.LookDirAngles);

        var isGrounded = IsPlayerGrounded(playerObjectComponent);

        if (isGrounded)
        {
            var relativeMoveDirection     = GetRelativeMoveDirection(playerObjectState.Input);
            var playerYAngle              = playerObjectComponent.transform.eulerAngles.y;
            var horizontalMoveDirection   = Quaternion.Euler(new Vector3(0, playerYAngle, 0)) * relativeMoveDirection;
            var desiredHorizontalVelocity = OsFps.MaxPlayerMovementSpeed * horizontalMoveDirection;
            var currentHorizontalVelocity = GameObjectExtensions.GetHorizontalVelocity(playerObjectComponent.Rigidbody);
            var horizontalVelocityError   = desiredHorizontalVelocity - currentHorizontalVelocity;

            playerObjectComponent.Rigidbody.AddForce(3000 * horizontalVelocityError);
        }
    }