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

@@ -19,7 +19,8 @@ namespace OnlyScove.Scripts
public override void Tick(float deltaTime)
{
Vector2 input = stateMachine.Input.MoveInput;
// ĐÚNG: Sử dụng dữ liệu đã đồng bộ qua mạng
Vector2 input = stateMachine.MoveInput;
float moveAmount = Mathf.Clamp01(Mathf.Abs(input.x) + Mathf.Abs(input.y));
if (moveAmount <= 0.01f)
@@ -28,14 +29,16 @@ namespace OnlyScove.Scripts
return;
}
if (!stateMachine.Input.IsSprintHeld)
if (!stateMachine.IsSprintHeld)
{
stateMachine.SwitchState(new PlayerMoveState(stateMachine));
return;
}
Vector3 inputDir = new Vector3(input.x, 0, input.y).normalized;
Vector3 moveDirection = stateMachine.Cam != null ? stateMachine.Cam.PlanarRotation * inputDir : inputDir;
Vector3 moveDirection = stateMachine.NetworkedCameraRotation * inputDir;
moveDirection.y = 0;
moveDirection.Normalize();
Vector3 velocity = moveDirection * stateMachine.SprintSpeed;
@@ -45,25 +48,13 @@ namespace OnlyScove.Scripts
}
else
{
stateMachine.VelocityY += Physics.gravity.y * deltaTime;
stateMachine.VelocityY += stateMachine.Gravity * deltaTime;
}
velocity.y = stateMachine.VelocityY;
stateMachine.Controller.Move(velocity * deltaTime);
if (moveDirection != Vector3.zero)
{
Quaternion targetRot = Quaternion.LookRotation(moveDirection);
stateMachine.transform.rotation = Quaternion.RotateTowards(
stateMachine.transform.rotation,
targetRot,
stateMachine.RotationSpeed * deltaTime
);
}
stateMachine.Anim.SetFloat(speedHash, 1f, stateMachine.AnimationDamping, deltaTime);
stateMachine.Anim.SetFloat(speedXHash, input.x * 2f, stateMachine.AnimationDamping, deltaTime);
stateMachine.Anim.SetFloat(speedZHash, input.y * 2f, stateMachine.AnimationDamping, deltaTime);
// Sử dụng hàm Move tập trung (1.0f là giá trị Speed cho Animator khi chạy)
stateMachine.Move(velocity, 1.0f, deltaTime);
stateMachine.Rotate(moveDirection, deltaTime);
}
public override void PhysicsTick(float fixedDeltaTime) {}