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

@@ -25,51 +25,34 @@ namespace OnlyScove.Scripts
public override void Enter()
{
// Set initial velocity for the Jump Blend Tree (2D Freeform)
Vector2 input = stateMachine.Input.MoveInput;
stateMachine.Anim.SetFloat(speedXHash, input.x);
stateMachine.Anim.SetFloat(speedZHash, input.y);
// Set Speed parameter to help distinguish between Idle Jump (0) and Run Jump (0.7+)
float moveAmount = input.magnitude;
stateMachine.Anim.SetFloat(speedHash, moveAmount > 0.1f ? 1.0f : 0f);
// Sử dụng dữ liệu đồng bộ
Vector2 input = stateMachine.MoveInput;
stateMachine.Anim.ResetTrigger(jumpHash);
stateMachine.Anim.SetTrigger(jumpHash);
// Physic formula: v = sqrt(h * -2 * g)
stateMachine.VelocityY = Mathf.Sqrt(stateMachine.JumpHeight * -2f * Physics.gravity.y);
stateMachine.VelocityY = Mathf.Sqrt(stateMachine.JumpHeight * -2f * stateMachine.Gravity);
stateMachine.Input.OnSprintEvent += OnAirDash;
}
public override void Tick(float deltaTime)
{
stateMachine.VelocityY += Physics.gravity.y * deltaTime;
stateMachine.VelocityY += stateMachine.Gravity * deltaTime;
Vector2 input = stateMachine.Input.MoveInput;
Vector2 input = stateMachine.MoveInput;
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 * jumpSpeed;
velocity.y = stateMachine.VelocityY;
stateMachine.Controller.Move(velocity * deltaTime);
// Cập nhật Animator cho việc di chuyển trên không (Blend Tree sẽ tự mượt mà theo các giá trị này)
float multiplier = stateMachine.Input.IsSprintHeld ? 1f : 0.5f;
stateMachine.Anim.SetFloat(speedXHash, input.x * multiplier, stateMachine.AnimationDamping, deltaTime);
stateMachine.Anim.SetFloat(speedZHash, input.y * multiplier, stateMachine.AnimationDamping, deltaTime);
if (moveDirection != Vector3.zero)
{
Quaternion targetRot = Quaternion.LookRotation(moveDirection);
stateMachine.transform.rotation = Quaternion.RotateTowards(
stateMachine.transform.rotation,
targetRot,
stateMachine.RotationSpeed * deltaTime
);
}
// Đồng bộ di chuyển và xoay
stateMachine.Move(velocity, 1.0f, deltaTime);
stateMachine.Rotate(moveDirection, deltaTime);
if (stateMachine.VelocityY <= 0f)
{