Files
Cielonos/Assets/Scripts/MainGame/Characters/Player/PlayerLandMovementSubcontroller.cs

250 lines
8.7 KiB
C#
Raw Normal View History

2025-11-25 08:19:33 -05:00
using System;
2026-02-13 09:22:11 -05:00
using DG.Tweening;
using SLSUtilities.General;
2025-11-25 08:19:33 -05:00
using SLSUtilities.FunctionalAnimation;
using UniRx;
using UnityEngine;
namespace Cielonos.MainGame.Characters
{
2026-02-13 09:22:11 -05:00
public partial class PlayerLandMovementSubcontroller : LandMovementSubcontroller
2025-11-25 08:19:33 -05:00
{
public Player player => owner as Player;
2026-02-13 09:22:11 -05:00
private PlayerAnimationSubcontroller animationSc => base.animationSc as PlayerAnimationSubcontroller;
2025-11-25 08:19:33 -05:00
2026-01-12 03:22:16 -05:00
protected override void OnAnimatorMove()
2025-11-25 08:19:33 -05:00
{
if (DeltaTime == 0)
{
return;
}
Rotate();
Move();
Jump();
base.OnAnimatorMove();
InitiativeMove();
}
2026-02-13 09:22:11 -05:00
public void TurnToInputDirection(Vector3 direction, float duration = 0f)
{
Vector3 dashRotation = Vector3.zero;
float angle = Vector3.SignedAngle(Vector3.forward, direction, Vector3.up);
if (owner is Player player)
{
dashRotation.y = player.viewSc.playerCamera.transform.eulerAngles.y + angle;
}
else
{
dashRotation = new Vector3(0, angle, 0);
}
if (duration > 0)
{
characterTransform.DORotateQuaternion(Quaternion.Euler(dashRotation), duration).Play();
}
else
{
characterTransform.rotation = Quaternion.Euler(dashRotation);
}
}
2025-11-25 08:19:33 -05:00
}
public partial class PlayerLandMovementSubcontroller
{
void Rotate()
{
if (animationSc.isDuringRootMotion) return;
Vector3 inputDirection = new Vector3(player.inputSc.Move.x, 0.0f, player.inputSc.Move.y).normalized;
if (player.inputSc.IsMoving)
{
targetRotation = Mathf.Atan2(inputDirection.x, inputDirection.z) * Mathf.Rad2Deg +
player.viewSc.playerCamera.transform.eulerAngles.y;
2026-02-13 09:22:11 -05:00
if (rotationType == CharacterRotationType.ByMovement && canRotate.Value)
2025-11-25 08:19:33 -05:00
{
float rotation = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetRotation, ref rotationVelocity, rotationSmoothTime);
player.transform.rotation = Quaternion.Euler(0.0f, rotation, 0.0f);
}
}
targetDirection = Quaternion.Euler(0.0f, targetRotation, 0.0f) * Vector3.forward;
}
void Move()
{
2026-02-13 09:22:11 -05:00
if (!canMove.Value)
2025-11-25 08:19:33 -05:00
{
moveSpeed = 0;
return;
}
2026-03-20 12:07:44 -04:00
float targetSpeed = player.attributeSm.Get(CharacterAttribute.MovementSpeed, 10f) * (isSprinting ? sprintSpeedMultiplier : 1f);
2025-11-25 08:19:33 -05:00
float movementAnimationSpeedMultiplier = !player.inputSc.IsWalking && targetSpeed > 10f ? targetSpeed / 10f : 1;
float inputMagnitude = player.inputSc.Move.magnitude;
2026-03-20 12:07:44 -04:00
moveAcceleration = player.attributeSm.Get("MoveAcceleration", 6);
moveDeceleration = player.attributeSm.Get("MoveDeceleration", 8);
2025-11-25 08:19:33 -05:00
if (player.inputSc.IsMoving)
{
bool success = animationSc.fullBodyFuncAnimSm.Stop(DisruptionType.Movement, 0.25f);
if (!success && animationSc.isDuringRootMotion)
{
if (!isDashing)
{
moveSpeed = Mathf.Lerp(moveSpeed, 0, DeltaTime * moveDeceleration);
}
return;
}
}
else
{
isSprinting = false;
}
2026-01-03 18:19:39 -05:00
2025-11-25 08:19:33 -05:00
animator.SetFloat("MoveSpeedMultiplier", movementAnimationSpeedMultiplier);
if (!isRushStopping && !isJumpLanding && player.inputSc.IsMoving)
{
float finalTargetSpeed = !player.inputSc.IsWalking ? targetSpeed * inputMagnitude : 2f;
finalTargetSpeed = Mathf.Max(finalTargetSpeed, 1);
moveSpeed = Mathf.Lerp(moveSpeed, finalTargetSpeed, DeltaTime * moveAcceleration);
}
else if (!isDashing)
{
moveSpeed = Mathf.Lerp(moveSpeed, 0, DeltaTime * moveDeceleration);
}
/*if (MotionController.characterRotationType == PlayerMotionController.CharacterRotationType.ByAiming)
{
mx = Mathf.Lerp(mx, Player.inputController.InputMoveValue.x, DeltaTime * movementSpeedAccelerationRate);
my = Mathf.Lerp(my, Player.inputController.InputMoveValue.y, DeltaTime * movementSpeedAccelerationRate);
Player.animator.SetFloat("MovementSpeedX", mx * movementSpeed);
Player.animator.SetFloat("MovementSpeedZ", my * movementSpeed);
}
else
*/
{
animator.SetFloat("MoveSpeedZ", moveSpeed);
}
if (moveSpeed > 5f * DeltaTime && player.inputSc.IsMoving)
{
runningTime += DeltaTime;
}
else
{
runningTime = 0;
}
}
2026-01-17 11:35:49 -05:00
private void Jump()
2025-11-25 08:19:33 -05:00
{
2026-02-13 09:22:11 -05:00
if (player.inputSc.JumpPressed && animationSc.fullBodyFuncAnimSm.Stop(DisruptionType.NormalAction))
2025-11-25 08:19:33 -05:00
{
2026-02-13 09:22:11 -05:00
if (!isJumping)
{
FirstJump();
}
else
{
ExtraJump(-1, true);
}
2025-11-25 08:19:33 -05:00
}
if (isJumping)
{
jumpTime += DeltaTime;
2026-02-13 09:22:11 -05:00
2025-11-25 08:19:33 -05:00
if (jumpVelocity > 0)
{
jumpVelocity -= jumpGravity * DeltaTime;
}
else
{
2026-02-13 09:22:11 -05:00
jumpVelocity = 0f;
gravitationalMovement += new Vector3(0, -jumpGravity * gravityMultiplier * DeltaTime, 0) * DeltaTime;
}
if (jumpTime > 0.1f)
{
if (jumpTime > 1f && groundDetector.DetectGround(4f, 1f))
2025-11-25 08:19:33 -05:00
{
2026-02-13 09:22:11 -05:00
jumpVelocity = 0f;
animationSc.grounderFBBIK.weight = 1;
isJumping = false;
movementModifier = Vector3.zero;
animator.SetBool("IsLandingOnGround", true);
animator.SetTrigger("LandFromHighAltitude");
isJumpLanding = true;
Observable.Timer(TimeSpan.FromSeconds(0.4f)).Subscribe(_ => { isJumpLanding = false; });
return;
}
if(groundDetector.isOnGround || groundDetector.DetectGround())
{
jumpVelocity = 0f;
animationSc.grounderFBBIK.weight = 1;
2025-11-25 08:19:33 -05:00
animator.SetBool("IsLandingOnGround", true);
isJumping = false;
movementModifier = Vector3.zero;
}
}
}
}
2026-01-17 11:35:49 -05:00
public void FirstJump()
{
2026-02-13 09:22:11 -05:00
if(isStartJumping || isJumping || !groundDetector.isOnGround)
2026-01-17 11:35:49 -05:00
{
return;
}
animator.SetTrigger("Jump");
2026-02-13 09:22:11 -05:00
(animationSc as PlayerAnimationSubcontroller).grounderFBBIK.weight = 0;
isStartJumping = true;
2026-01-17 11:35:49 -05:00
player.eventSm.onFirstJump.Invoke();
player.selfTimeSm.AddLocalTimer(0.16f, () =>
{
jumpVelocity = jumpForce;
2026-02-13 09:22:11 -05:00
isStartJumping = false;
2026-01-17 11:35:49 -05:00
isJumping = true;
jumpTime = 0;
jumpHeldTime = 0;
2026-02-13 09:22:11 -05:00
gravitationalMovement = Vector3.zero;
2026-01-17 11:35:49 -05:00
animator.SetBool("IsLandingOnGround", false);
});
}
2026-02-13 09:22:11 -05:00
public void ExtraJump(float overrideForce = -1, bool hasAnimation = false, bool isAdditive = true)
2026-01-17 11:35:49 -05:00
{
if (!isAdditive)
{
jumpVelocity = overrideForce > 0 ? overrideForce : jumpForce;
}
else
{
jumpVelocity += overrideForce > 0 ? overrideForce : jumpForce;
}
2026-02-13 09:22:11 -05:00
2026-01-17 11:35:49 -05:00
isJumping = true;
2026-02-13 09:22:11 -05:00
gravitationalMovement = Vector3.zero;
2026-01-17 11:35:49 -05:00
}
2025-11-25 08:19:33 -05:00
protected override void UpdateFinalMovement()
{
base.UpdateFinalMovement();
float horizontalSpeed = horizontalMovement.magnitude / DeltaTime;
float remapFactor = Mathf.InverseLerp(10f, 15f, horizontalSpeed);
PostProcessingManager.Instance.speedLinesSm.SetRemap(1 - remapFactor);
}
}
}