update mutiplay
This commit is contained in:
@@ -32,36 +32,25 @@ namespace OnlyScove.Scripts
|
||||
|
||||
public override void Tick(float deltaTime)
|
||||
{
|
||||
stateMachine.VelocityY += Physics.gravity.y * deltaTime;
|
||||
stateMachine.VelocityY += stateMachine.Gravity * deltaTime;
|
||||
|
||||
Vector2 input = stateMachine.Input.MoveInput;
|
||||
// ĐÚNG: Sử dụng MoveInput đã đồng bộ mạng
|
||||
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 * fallSpeed;
|
||||
velocity.y = stateMachine.VelocityY;
|
||||
|
||||
stateMachine.Controller.Move(velocity * deltaTime);
|
||||
|
||||
// Cập nhật Animator cho việc rơi trên không
|
||||
float multiplier = stateMachine.Input.IsSprintHeld ? 2f : 0.5f;
|
||||
stateMachine.Anim.SetFloat(speedHash, stateMachine.Input.IsSprintHeld ? 1f : 0.7f, stateMachine.AnimationDamping, deltaTime);
|
||||
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
|
||||
);
|
||||
}
|
||||
// Sử dụng hàm Move tập trung của StateMachine để đồng bộ
|
||||
stateMachine.Move(velocity, 0.5f, deltaTime);
|
||||
stateMachine.Rotate(moveDirection, deltaTime);
|
||||
|
||||
if (stateMachine.IsGrounded)
|
||||
{
|
||||
// Landing Shake from PlayerController.cs
|
||||
// Landing Shake
|
||||
if (!stateMachine.WasGrounded && stateMachine.VelocityY < -1f)
|
||||
{
|
||||
if (stateMachine.Cam != null)
|
||||
@@ -76,8 +65,7 @@ namespace OnlyScove.Scripts
|
||||
stateMachine.SwitchState(new PlayerIdleState(stateMachine));
|
||||
else
|
||||
{
|
||||
// Return to the appropriate movement state based on sprint input
|
||||
if (stateMachine.Input.IsSprintHeld)
|
||||
if (stateMachine.IsSprintHeld)
|
||||
stateMachine.SwitchState(new PlayerRunState(stateMachine));
|
||||
else
|
||||
stateMachine.SwitchState(new PlayerMoveState(stateMachine));
|
||||
|
||||
Reference in New Issue
Block a user