private static MovementData UpdateHorizontal(ref MovementData movementData, PlayerInputData inputData, PlayerMovementAbilityData movementAbilityData, float deltaTime, PlayerStates states) { var vel = movementData.Velocity; var maxHorizontalSpeed = inputData.FireKeep ? movementAbilityData.MaxHorizontalSpeedDashing : movementAbilityData.MaxHorizontalSpeed; var horizontalAcc = inputData.FireKeep ? movementAbilityData.HorizontalDashingAcc : movementAbilityData.HorizontalAcc; if (inputData.HorizontalInput != 0) { vel.x = math.clamp(vel.x + inputData.HorizontalInput * horizontalAcc * deltaTime, -maxHorizontalSpeed, maxHorizontalSpeed); } else if (PlayerUtility.IsGrounded(states)) { var sign = math.sign(vel.x); var value = math.abs(vel.x); var amountToReduce = movementAbilityData.HorizontalReverseAcc * deltaTime; value = value < amountToReduce ? 0 : value - amountToReduce; vel.x = sign * value; } movementData.Velocity = vel; return(movementData); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { Entities.WithAll <PlayerTag>().WithoutBurst().ForEach((ref PlayerStates states, in MovementData movementData) => { if (states.Main != PlayerMainStatus.Alive) { return; } var wasGrounded = PlayerUtility.IsGrounded(states); var lastMotionStatus = states.Motion; if (states.FallingStopped || wasGrounded && math.abs(movementData.Velocity.y) < float.Epsilon) { if (math.abs(movementData.Velocity.x) < float.Epsilon) { states.Motion = PlayerMotionStatus.Static; } else { states.Motion = PlayerMotionStatus.Running; } } else { if (movementData.Velocity.y > 0) { states.Motion = PlayerMotionStatus.Jumping; } else { states.Motion = PlayerMotionStatus.Falling; } } // Reset flags. states.FallingStopped = false; if (states.Motion != PlayerMotionStatus.Jumping) { states.JumpKeepTime = 0; } if (lastMotionStatus != states.Motion) { var eventArgs = GameEntry.Instance.RefPool.GetOrAdd <PlayerMotionStatusChangeEventArgs>().Acquire(); eventArgs.LastMotionStatus = lastMotionStatus; eventArgs.PlayerStates = states; GameEntry.Instance.Event.SendEvent(this, eventArgs); } }).Run(); return(default);
private void OnPlayerMotionStatusChange(object sender, BaseEventArgs e) { var eventArgs = (PlayerMotionStatusChangeEventArgs)e; if (PlayerUtility.IsGrounded(eventArgs.PlayerStates) && PlayerUtility.IsInAir(eventArgs.LastMotionStatus)) { AudioManager.StopSoundEffect("smb_jump-small"); AudioManager.StopSoundEffect("smb_jump-super"); } if (eventArgs.PlayerStates.Motion == PlayerMotionStatus.Jumping && !AudioManager.IsPlayingSoundEffect("smb_stomp")) { AudioManager.PlaySoundEffect(eventArgs.PlayerStates.Level == PlayerLevel.Default ? "smb_jump-small" : "smb_jump-super"); } }
protected override JobHandle OnUpdate(JobHandle inputDeps) { var deltaTime = TimeUtility.GetLimitedDeltaTime(); return(Entities.WithAll <PlayerTag>().ForEach(( ref Translation translation, ref MovementData movementData, ref PlayerStates states, ref PlayerBouncedByEnemyData bouncedByEnemyData, ref PlayerInputData inputData, in PlayerMovementAbilityData movementAbilityData) => { if (states.Main == PlayerMainStatus.Dying) { return; } UpdateHorizontal(ref movementData, inputData, movementAbilityData, deltaTime, states); if (PlayerUtility.IsGrounded(states)) { UpdateJumpStart(ref states, ref movementData, inputData, movementAbilityData); } else if (states.Motion == PlayerMotionStatus.Jumping) { UpdateJumpKeep(ref states, ref movementData, movementAbilityData, inputData, deltaTime); } else if (states.Motion == PlayerMotionStatus.Falling) { UpdateBouncedByEnemy(ref bouncedByEnemyData, ref states, ref inputData, ref movementData, movementAbilityData); } bouncedByEnemyData.IsBounced = false; }).Schedule(inputDeps)); }