update MUTIPLAY
This commit is contained in:
@@ -20,7 +20,8 @@ namespace OnlyScove.Scripts
|
||||
|
||||
public override void Tick(float deltaTime)
|
||||
{
|
||||
Vector2 input = stateMachine.Input.MoveInput;
|
||||
// QUAN TRỌNG: Đọc trực tiếp từ stateMachine (Dữ liệu đã đồng bộ mạng)
|
||||
Vector2 input = stateMachine.MoveInput;
|
||||
float moveAmount = Mathf.Clamp01(Mathf.Abs(input.x) + Mathf.Abs(input.y));
|
||||
|
||||
if (moveAmount <= 0.01f)
|
||||
@@ -29,25 +30,17 @@ namespace OnlyScove.Scripts
|
||||
return;
|
||||
}
|
||||
|
||||
if (stateMachine.Input.IsSprintHeld)
|
||||
if (stateMachine.IsSprintHeld)
|
||||
{
|
||||
stateMachine.SwitchState(new PlayerDashState(stateMachine));
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 inputDir = new Vector3(input.x, 0, input.y).normalized;
|
||||
|
||||
// DÙNG HƯỚNG CAMERA TỪ MẠNG ĐỂ ĐỒNG BỘ MÁY CHỦ
|
||||
Vector3 moveDirection = stateMachine.NetworkedCameraRotation * inputDir;
|
||||
moveDirection.y = 0; // Đảm bảo không bay lên trời
|
||||
moveDirection.y = 0;
|
||||
moveDirection.Normalize();
|
||||
|
||||
if (stateMachine.Cam != null && stateMachine.Object.HasInputAuthority)
|
||||
{
|
||||
// Log chỉ hiện ở máy khách để debug hướng xoay
|
||||
// Debug.Log($"[Move] Input: {inputDir}, MoveDir: {moveDirection}");
|
||||
}
|
||||
|
||||
Vector3 velocity = moveDirection * stateMachine.WalkSpeed;
|
||||
|
||||
if (stateMachine.IsGrounded && stateMachine.VelocityY < 0)
|
||||
@@ -56,11 +49,12 @@ namespace OnlyScove.Scripts
|
||||
}
|
||||
else
|
||||
{
|
||||
stateMachine.VelocityY += Physics.gravity.y * deltaTime;
|
||||
stateMachine.VelocityY += stateMachine.Gravity * deltaTime;
|
||||
}
|
||||
velocity.y = stateMachine.VelocityY;
|
||||
|
||||
stateMachine.Controller.Move(velocity * deltaTime);
|
||||
// DÙNG HÀM MOVE TẬP TRUNG ĐỂ ĐỒNG BỘ TỐC ĐỘ VỚI MẠNG
|
||||
stateMachine.Move(velocity, 0.7f, deltaTime);
|
||||
|
||||
if (moveDirection != Vector3.zero)
|
||||
{
|
||||
@@ -71,10 +65,6 @@ namespace OnlyScove.Scripts
|
||||
stateMachine.RotationSpeed * deltaTime
|
||||
);
|
||||
}
|
||||
|
||||
stateMachine.Anim.SetFloat(speedHash, 0.7f, stateMachine.AnimationDamping, deltaTime);
|
||||
stateMachine.Anim.SetFloat(speedXHash, input.x * 0.5f, stateMachine.AnimationDamping, deltaTime);
|
||||
stateMachine.Anim.SetFloat(speedZHash, input.y * 0.5f, stateMachine.AnimationDamping, deltaTime);
|
||||
}
|
||||
|
||||
public override void PhysicsTick(float fixedDeltaTime) {}
|
||||
|
||||
Reference in New Issue
Block a user