update di chuyển debug jump
This commit is contained in:
@@ -32,12 +32,12 @@ namespace OnlyScove.Scripts
|
||||
|
||||
public float VelocityY
|
||||
{
|
||||
get => (Object != null && Object.IsValid && Movement != null) ? Movement.VelocityY : 0f;
|
||||
set { if (Object != null && Object.IsValid && Movement != null) Movement.VelocityY = value; }
|
||||
get => (Movement != null) ? Movement.VelocityY : 0f;
|
||||
set { if (Movement != null) Movement.VelocityY = value; }
|
||||
}
|
||||
|
||||
public bool IsGrounded => (Object != null && Object.IsValid && Movement != null) ? Movement.IsGrounded : true;
|
||||
public bool WasGrounded => (Object != null && Object.IsValid && Movement != null) ? Movement.WasGrounded : true;
|
||||
public bool IsGrounded => (Movement != null) ? Movement.IsGrounded : true;
|
||||
public bool WasGrounded => (Movement != null) ? Movement.WasGrounded : true;
|
||||
|
||||
public float WalkSpeed => Movement.WalkSpeed;
|
||||
public float RunSpeed => Movement.RunSpeed;
|
||||
@@ -106,6 +106,7 @@ namespace OnlyScove.Scripts
|
||||
if (isOffline || (Object != null && Object.HasInputAuthority))
|
||||
{
|
||||
Local = this;
|
||||
|
||||
CameraController cameraController = GameObject.FindAnyObjectByType<CameraController>();
|
||||
if (cameraController != null)
|
||||
{
|
||||
@@ -161,7 +162,9 @@ namespace OnlyScove.Scripts
|
||||
bool isNetworked = Runner != null && Runner.IsRunning && Object != null && Object.IsValid;
|
||||
float speedValue = (!isNetworked || Object.HasInputAuthority) ? localAnimatorSpeed : NetworkedSpeed;
|
||||
Vector2 inputVector = (!isNetworked || Object.HasInputAuthority) ? MoveInput : NetworkedMoveInput;
|
||||
AnimationHandler.UpdateAnimator(speedValue, inputVector, deltaTime);
|
||||
|
||||
// Pass IsGrounded to handle air/ground transitions
|
||||
AnimationHandler.UpdateAnimator(speedValue, inputVector, IsGrounded, deltaTime);
|
||||
}
|
||||
|
||||
public override void FixedUpdateNetwork()
|
||||
@@ -169,38 +172,64 @@ namespace OnlyScove.Scripts
|
||||
bool isRunning = Runner != null && Runner.IsRunning;
|
||||
if (isRunning && (Object == null || !Object.IsValid)) return;
|
||||
|
||||
float deltaTime = isRunning ? Runner.DeltaTime : Time.fixedDeltaTime;
|
||||
|
||||
if (GetInput(out PlayerInputData data))
|
||||
{
|
||||
MoveInput = data.Direction;
|
||||
IsSprintHeld = (bool)data.sprint;
|
||||
if (isRunning) NetworkedCameraRotation = data.rot;
|
||||
|
||||
if (data.jump) TriggerJump();
|
||||
}
|
||||
else if (!isRunning)
|
||||
{
|
||||
MoveInput = new Vector2(UnityEngine.Input.GetAxisRaw("Horizontal"), UnityEngine.Input.GetAxisRaw("Vertical"));
|
||||
IsSprintHeld = UnityEngine.Input.GetKey(KeyCode.LeftShift);
|
||||
if (Input.ConsumeJumpInput()) TriggerJump();
|
||||
}
|
||||
|
||||
if (!isRunning || (Object != null && Object.IsValid && (Object.HasInputAuthority || Runner.IsServer)))
|
||||
{
|
||||
if (hasControl)
|
||||
{
|
||||
Movement.CheckGround(transform);
|
||||
Movement.CheckGround(transform, deltaTime);
|
||||
Interaction.UpdateInteractables();
|
||||
currentState?.Tick(isRunning ? Runner.DeltaTime : Time.fixedDeltaTime);
|
||||
currentState?.Tick(deltaTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void TriggerJump()
|
||||
{
|
||||
if (!IsGrounded) return;
|
||||
|
||||
if (Scanner != null)
|
||||
{
|
||||
var hitData = Scanner.ObstacleCheck();
|
||||
if (hitData.forwardHitFound && hitData.heightHitFound)
|
||||
{
|
||||
SwitchState(new PlayerParkourState(this));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
float jumpMoveSpeed = (IsSprintHeld) ? Movement.SprintSpeed : Movement.WalkSpeed;
|
||||
SwitchState(new PlayerJumpState(this, jumpMoveSpeed));
|
||||
}
|
||||
|
||||
public override void Render()
|
||||
{
|
||||
bool isRunning = Runner != null && Runner.IsRunning;
|
||||
if (isRunning && Object != null && Object.IsValid && !Object.HasInputAuthority)
|
||||
if (isRunning && Object != null && Object.IsValid)
|
||||
{
|
||||
// Smooth interpolation for proxies
|
||||
if (Movement.NetworkedPosition != Vector3.zero)
|
||||
if (!Object.HasInputAuthority)
|
||||
{
|
||||
transform.position = Vector3.Lerp(transform.position, Movement.NetworkedPosition, Runner.DeltaTime * 15f);
|
||||
// Proxies
|
||||
if (Movement.NetworkedPosition != Vector3.zero)
|
||||
{
|
||||
transform.position = Vector3.Lerp(transform.position, Movement.NetworkedPosition, Runner.DeltaTime * 20f);
|
||||
}
|
||||
}
|
||||
UpdateAnimator(Runner.DeltaTime);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user