35 float horizontalDiagonalLength =
Math.Sqrt(
Pow2(maxs[0] - mins[0]) +
Pow2(maxs[2] - mins[2]));
36 float cuboidDiagonalLength =
Math.Sqrt(
Pow2(horizontalDiagonalLength) +
Pow2(maxs[1] - mins[1]));
39 if (SCR_ChimeraCharacter.Cast(entity))
41 horizontalDiagonalLength *= CHARACTER_BOUNDING_RADIUS_MODIFIER;
42 cuboidDiagonalLength *= CHARACTER_SPACING_MODIFIER;
46 traceParam.Radius = 0.5 * horizontalDiagonalLength;
47 traceParam.Exclude = entity;
48 float entityHeight = maxs[1] - mins[1];
49 float spacing = 2 * cuboidDiagonalLength;
50 float maxHorizontalDistance = 10 * spacing;
51 float maxSubmersionDepth = 0.5 * entityHeight;
58 PrintFormat(
"[SCR_EmptyPositionHelper] TryFindNearbyFloorPositionForEntity failed for find space nearby %1 for %2",
position, entity, level:
LogLevel.WARNING);
76 if (!traceParam.Flags)
83 if (traceParam.LayerMask == -1)
84 traceParam.LayerMask = EPhysicsLayerDefs.Projectile;
87 if (
float.AlmostEqual(traceHeight, 0))
98 float halfSpacing = 0.5 * spacing;
99 int maxSpheres =
Math.Min(
Math.Ceil(maxDistance / spacing), SPHERE_AMOUNT_LIMIT);
100 for (
int sphereI = 1; sphereI <= maxSpheres; ++sphereI)
102 float unitSpacing = 1 / sphereI;
104 float radius = sphereI * spacing;
105 for (
int pointI = 0; pointI < pointsAmount; ++pointI)
108 float terrainHeight = world.GetSurfaceY(point[0], point[2]);
110 if (point[1] < terrainHeight + TRACE_EPSILON)
112#ifdef SCR_EMPTY_POSITION_HELPER_DEBUG_SHAPES
113 SCR_DebugShapeHelperComponent.AddText(world,
position,
"Underground", tag:
DEBUG_TAG);
118 float oceanHeight = world.GetOceanHeight(point[0], point[2]);
121 point[1] =
Math.Max(oceanHeight + TRACE_EPSILON, point[1]);
125 if (point[1] < oceanHeight + TRACE_EPSILON)
127#ifdef SCR_EMPTY_POSITION_HELPER_DEBUG_SHAPES
128 SCR_DebugShapeHelperComponent.AddText(world,
position,
"Underwater", tag:
DEBUG_TAG);
164 if (
float.AlmostEqual(traceHeight, 0))
166 float halfTraceHeight = 0.5 * traceHeight;
167 bonusTraceLength =
Math.Min(bonusTraceLength, MAX_SCAN_LENGTH);
168 float surfaceHeightWithBuffer = world.GetSurfaceY(
position[0],
position[2]) + traceHeight + TRACE_EPSILON;
171 traceParam.End =
position -
Vector(0,
Math.Max(MAX_SCAN_LENGTH, minHeight - traceHeight), 0);
175 if (floorPos == traceParam.Start)
178#ifdef SCR_EMPTY_POSITION_HELPER_DEBUG_SHAPES
179 SCR_DebugShapeHelperComponent.CreateFloorCeilingTraceShapes(world,
position, traceParam, floorPos, ceilingPos,
false,
"Floor clipped", tag:
DEBUG_TAG);
185 floorPos -=
Vector(0, halfTraceHeight, 0);
190#ifdef SCR_EMPTY_POSITION_HELPER_DEBUG_SHAPES
191 SCR_DebugShapeHelperComponent.CreateFloorCeilingTraceShapes(world,
position, traceParam, floorPos, ceilingPos,
false,
"No floor", tag:
DEBUG_TAG);
196 if (floorPos[1] < minFloorY)
199#ifdef SCR_EMPTY_POSITION_HELPER_DEBUG_SHAPES
200 SCR_DebugShapeHelperComponent.CreateFloorCeilingTraceShapes(world,
position, traceParam, floorPos, ceilingPos,
false,
"Floor too low", tag:
DEBUG_TAG);
205 float remainingScanLength = minHeight - (
position[1] - floorPos[1]) - halfTraceHeight;
206 if (remainingScanLength + bonusTraceLength < 0)
209#ifdef SCR_EMPTY_POSITION_HELPER_DEBUG_SHAPES
210 SCR_DebugShapeHelperComponent.CreateFloorCeilingTraceShapes(world,
position, traceParam, floorPos, ceilingPos,
true,
"Enough height, skipped ceiling", tag:
DEBUG_TAG);
216 traceParam.End =
position +
Vector(0, remainingScanLength + bonusTraceLength, 0);
220 if (ceilingPos == traceParam.Start)
222#ifdef SCR_EMPTY_POSITION_HELPER_DEBUG_SHAPES
223 SCR_DebugShapeHelperComponent.CreateFloorCeilingTraceShapes(world,
position, traceParam, floorPos, ceilingPos,
false,
"Ceiling clipped", tag:
DEBUG_TAG);
229 ceilingPos +=
Vector(0, halfTraceHeight, 0);
231 bool enoughSpace = (ceilingPos[1] - floorPos[1]) >= minHeight;
232#ifdef SCR_EMPTY_POSITION_HELPER_DEBUG_SHAPES
234 SCR_DebugShapeHelperComponent.CreateFloorCeilingTraceShapes(world,
position, traceParam, floorPos, ceilingPos, enoughSpace,
"Good position", tag:
DEBUG_TAG);
236 SCR_DebugShapeHelperComponent.CreateFloorCeilingTraceShapes(world,
position, traceParam, floorPos, ceilingPos, enoughSpace,
"Insufficient height", tag:
DEBUG_TAG);
346 float traceMinRadius = 0.1;
350 traceMinRadius = 0.5 *
Math.Min(
Math.Min(traceBox.Maxs[0] - traceBox.Mins[0], traceBox.Maxs[1] - traceBox.Mins[1]), traceBox.Maxs[2] - traceBox.Mins[2]);
356 traceMinRadius = traceSphere.Radius;
360 preTraceParam.Flags = traceParam.Flags;
361 preTraceParam.LayerMask = traceParam.LayerMask;
362 preTraceParam.Radius = 0.1 * traceMinRadius;
363 preTraceParam.Exclude = traceParam.Exclude;
364 preTraceParam.ExcludeArray = traceParam.ExcludeArray;
365 preTraceParam.Include = traceParam.Include;
366 preTraceParam.IncludeArray = traceParam.IncludeArray;
367 return preTraceParam;