Add prototype gameplay loop with character/battlefield assets and server game APIs.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -13,35 +13,44 @@ namespace HotUpdate
|
||||
public static float Height(Vector3 xz, Transform searchRoot = null, float fallback = 0f)
|
||||
{
|
||||
Physics.SyncTransforms();
|
||||
var cols = Collect(searchRoot);
|
||||
var offsets = new[]
|
||||
{
|
||||
Vector3.zero,
|
||||
new Vector3(0.35f, 0f, 0.35f),
|
||||
new Vector3(-0.35f, 0f, 0.35f),
|
||||
new Vector3(0.35f, 0f, -0.35f),
|
||||
};
|
||||
foreach (var offset in offsets)
|
||||
{
|
||||
if (TryHit(cols, xz + offset, groundOnly: true, out var y))
|
||||
return y;
|
||||
}
|
||||
foreach (var offset in offsets)
|
||||
{
|
||||
if (TryHit(cols, xz + offset, groundOnly: false, out var y))
|
||||
return y;
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
static bool TryHit(MeshCollider[] cols, Vector3 xz, bool groundOnly, out float y)
|
||||
{
|
||||
var ray = new Ray(new Vector3(xz.x, RayStartY, xz.z), Vector3.down);
|
||||
var bestDist = float.MaxValue;
|
||||
var y = fallback;
|
||||
y = 0f;
|
||||
var hitAny = false;
|
||||
|
||||
foreach (var col in Collect(searchRoot))
|
||||
foreach (var col in cols)
|
||||
{
|
||||
if (col == null || !col.enabled) continue;
|
||||
if (!IsGroundCollider(col)) continue;
|
||||
if (groundOnly && !IsGroundCollider(col)) continue;
|
||||
if (!col.Raycast(ray, out var hit, RayLength)) continue;
|
||||
if (hit.distance >= bestDist) continue;
|
||||
bestDist = hit.distance;
|
||||
y = hit.point.y;
|
||||
hitAny = true;
|
||||
}
|
||||
|
||||
if (hitAny) return y;
|
||||
|
||||
foreach (var col in Collect(searchRoot))
|
||||
{
|
||||
if (col == null || !col.enabled) continue;
|
||||
if (!col.Raycast(ray, out var hit, RayLength)) continue;
|
||||
if (hit.distance >= bestDist) continue;
|
||||
bestDist = hit.distance;
|
||||
y = hit.point.y;
|
||||
hitAny = true;
|
||||
}
|
||||
|
||||
return hitAny ? y : fallback;
|
||||
return hitAny;
|
||||
}
|
||||
|
||||
static MeshCollider[] Collect(Transform searchRoot)
|
||||
|
||||
Reference in New Issue
Block a user