update mutiplay

This commit is contained in:
2026-04-08 12:38:39 +07:00
parent e6deb358df
commit 8ef5ecbe0f
10 changed files with 138 additions and 180 deletions

View File

@@ -1,11 +1,11 @@
using UnityEngine;
using UnityEngine;
namespace OnlyScove.Scripts
{
public class PlayerDodgeState : PlayerBaseState
{
private readonly int dodgeHash = Animator.StringToHash("Dodge");
private float dodgeDuration = 0.4f; // Adjust based on your dodge animation length
private float dodgeDuration = 0.5f;
private float dodgeTimer;
private Vector3 dodgeDirection;
@@ -16,46 +16,32 @@ namespace OnlyScove.Scripts
dodgeTimer = dodgeDuration;
stateMachine.Anim.SetTrigger(dodgeHash);
// Calculate dodge direction based on current input
Vector2 input = stateMachine.Input.MoveInput;
Vector2 input = stateMachine.MoveInput;
if (input != Vector2.zero)
{
// Dodge in the input direction (Left, Right, Back, Forward)
dodgeDirection = new Vector3(input.x, 0f, input.y).normalized;
if (stateMachine.Cam != null)
{
dodgeDirection = stateMachine.Cam.PlanarRotation * dodgeDirection;
}
// Instantly rotate the player to face the dodge direction
stateMachine.transform.rotation = Quaternion.LookRotation(dodgeDirection);
dodgeDirection = new Vector3(input.x, 0, input.y).normalized;
dodgeDirection = stateMachine.NetworkedCameraRotation * dodgeDirection;
}
else
{
// If no input, just roll straight forward
dodgeDirection = stateMachine.transform.forward;
dodgeDirection = -stateMachine.transform.forward;
}
dodgeDirection.y = 0;
dodgeDirection.Normalize();
stateMachine.transform.rotation = Quaternion.LookRotation(dodgeDirection);
}
public override void Tick(float deltaTime)
{
dodgeTimer -= deltaTime;
// Apply movement force for the dodge (usually slightly slower than a Dash)
stateMachine.Controller.Move(dodgeDirection * (stateMachine.DashForce * 0.8f) * deltaTime);
// Sử dụng hàm Move tập trung
stateMachine.Move(dodgeDirection * (stateMachine.DashForce * 0.8f), 1.0f, deltaTime);
// Once the roll finishes, transition back to Idle or Move
if (dodgeTimer <= 0f)
if (dodgeTimer <= 0)
{
if (stateMachine.Input.MoveInput != Vector2.zero)
{
stateMachine.SwitchState(new PlayerMoveState(stateMachine));
}
else
{
stateMachine.SwitchState(new PlayerIdleState(stateMachine));
}
stateMachine.SwitchState(new PlayerIdleState(stateMachine));
}
}