// INERNALS private void ComputeTimeScale(out FP o_TimeScale) { o_TimeScale = FP.One; //bool slowMotionEnabled; //GameSettings.TryGetBoolMain(Settings.s_SlowMotionSetting, out slowMotionEnabled); if (m_Reference == null || m_ReferenceTransform == null /*|| !slowMotionEnabled*/) { return; } TSVector2 velocity = m_Reference.velocity; if (velocity.LengthSquared() < m_MinReferenceSpeed * m_MinReferenceSpeed) { o_TimeScale = 1f; return; } if (m_UseRaycast) { TSVector2 rayOrigin = m_Reference.position; TSVector2 rayDirection = velocity.normalized; FP speed = velocity.magnitude; FP rayDistance = speed * m_TimeToReach; rayDistance = MathFP.Max(rayDistance, m_DistanceThreshold); TSRaycastHit2D[] raycastHit = TSPhysics2D.Raycast(rayOrigin, rayDirection, rayDistance, m_RaycastMask); if (raycastHit == null || raycastHit.Length == 0) { o_TimeScale = 1f; return; } TSRaycastHit2D hitResult = raycastHit[0]; FP timeScale = MathFP.GetClampedPercentage(hitResult.distance, m_MinDistance, m_MaxDistance); timeScale = MathFP.Max(timeScale, m_MinTimeScale); o_TimeScale = timeScale; } else // Do a simple line check. { TSVector2 delta = velocity * m_TimeToReach; if (delta.magnitude > m_DistanceThreshold) { delta = delta.normalized * m_DistanceThreshold; } TSVector2 rayStart = m_Reference.position; TSVector2 rayEnd = rayStart + delta; // Check each stored segment. for (int segmentIndex = 0; segmentIndex < m_SegmentCount; ++segmentIndex) { TSVector2 pointA = m_Segments[segmentIndex * 2]; TSVector2 pointB = m_Segments[segmentIndex * 2 + 1]; FP t; TSVector2 intersectionPoint; if (Test2DSegmentSegment(pointA, pointB, rayStart, rayEnd, out t, out intersectionPoint)) { TSVector2 distance = intersectionPoint - rayStart; FP timeScale = MathFP.GetClampedPercentage(distance.magnitude, m_MinDistance, m_MaxDistance); timeScale = MathFP.Max(timeScale, m_MinTimeScale); o_TimeScale = timeScale; return; } } } }
public override void OnSyncedUpdate() { base.OnSyncedUpdate(); if (!m_RunSyncedUpdate) { return; } // Get delta time. FP deltaTime = TrueSyncManager.deltaTimeMain; // Update movement direction. FP horizontalAxis; FP verticalAxis; if (m_EnableInputCompression) { int intX = TrueSyncInput.GetInt(m_HorizontalAxisCode); int intY = TrueSyncInput.GetInt(m_VerticalAxisCode); horizontalAxis = intX / (FP)s_InputPrecision; verticalAxis = intY / (FP)s_InputPrecision; } else { horizontalAxis = TrueSyncInput.GetFP(m_HorizontalAxisCode); verticalAxis = TrueSyncInput.GetFP(m_VerticalAxisCode); } FP horizontalAxisAbs = MathFP.Abs(horizontalAxis); FP verticalAxisAbs = MathFP.Abs(verticalAxis); TSVector2 moveDirection = new TSVector2(horizontalAxis, verticalAxis); moveDirection.Normalize(); m_MoveDirection = moveDirection; // Update player action. if (m_CooldownTimer > FP.Zero) { m_CooldownTimer -= deltaTime; if (m_CooldownTimer < FP.Zero) { m_CooldownTimer = FP.Zero; } } if (m_CooldownTimer == FP.Zero) { bool buttonPressed = (TrueSyncInput.GetByte(m_ButtonPressedCode) > 0); if (buttonPressed) { m_PressureTime += deltaTime; m_ChargeLevel = MathFP.GetClampedPercentage(m_PressureTime, m_PressureTimeRange.min, m_PressureTimeRange.max); } else { if (m_PrevPressed) { FP axisThreshold = FP.One / FP.Ten; if (horizontalAxisAbs > axisThreshold || verticalAxisAbs > axisThreshold) { // Apply an insant force. FP requestForceMagnitude = MathFP.Lerp(m_ForceRange.min, m_ForceRange.max, m_ChargeLevel); TSVector2 moveForce = m_MoveDirection * requestForceMagnitude; m_Rigidbody2D.AddForce(moveForce); // Update cooldown timer. m_CooldownTimer = MathFP.Lerp(m_CooldownRange.min, m_CooldownRange.max, m_ChargeLevel); } else { m_CooldownTimer = FP.Zero; } } m_PressureTime = FP.Zero; m_ChargeLevel = FP.Zero; } m_PrevPressed = buttonPressed; } else { m_PressureTime = FP.Zero; m_ChargeLevel = FP.Zero; m_PrevPressed = false; } }