public static void Reflect(ISurfControllable surfer, float deltaTime) { var workingVel = surfer.MoveData.JustGrounded ? surfer.MoveData.PreGroundedVelocity : surfer.MoveData.Velocity; workingVel += surfer.MoveData.BaseVelocity; var clipped = false; //if (contactOffset != 0) //{ // var longSide = Mathf.Sqrt(contactOffset * contactOffset + contactOffset * contactOffset); // distance += longSide; // extents *= (1f - contactOffset); //} //var center = surfer.MoveData.Origin + new Vector3(0, surfer.Collider.bounds.extents.y, 0); //var end = center + (Vector3.down * 0.2f) + (workingVel * deltaTime); //var dist = Vector3.Distance(center, end); //var dir = (end - center).normalized; var center = surfer.MoveData.Origin + new Vector3(0, surfer.Collider.bounds.extents.y + 0.1f, 0); var dist = 0.2f; var dir = (Vector3.down + (workingVel * deltaTime)).normalized; //var dir = (Vector3.down + (workingVel * deltaTime)).normalized; var hitCount = Physics.BoxCastNonAlloc(results: _hits, center: center, direction: dir, orientation: surfer.Orientation, maxDistance: dist, halfExtents: surfer.Collider.bounds.extents, layerMask: GroundLayerMask, queryTriggerInteraction: QueryTriggerInteraction.Ignore); for (int i = 0; i < hitCount; i++) { if (Tracer.HitIsShit(_hits[i]) || _hits[i].collider == null) { continue; } if (_hits[i].normal.y <= SurfSlope || _hits[i].normal.y >= 1) { continue; } var slopeDir = Vector3.Cross(Vector3.up, Vector3.Cross(Vector3.up, _hits[i].normal)); var dot = Vector3.Dot(workingVel.normalized, slopeDir); var goingAgainstSlope = dot > 0; if (!goingAgainstSlope) { continue; } ClipVelocity(workingVel, _hits[i].normal, ref workingVel, 1f); clipped = true; } workingVel -= surfer.MoveData.BaseVelocity; if (clipped) { surfer.MoveData.Velocity = workingVel; } //var oldVelocityMagnitude2d = new Vector2(surfer.MoveData.Velocity.x, surfer.MoveData.Velocity.z).magnitude; // //var newVelocityMagnitude2d = new Vector2(surfer.MoveData.Velocity.x, surfer.MoveData.Velocity.z).magnitude; //float fLateralStoppingAmount = oldVelocityMagnitude2d - newVelocityMagnitude2d; //Debug.Log(fLateralStoppingAmount); }