Revamped collision system

This commit is contained in:
Jan Racek
2026-03-27 16:39:42 +01:00
parent d29ef569b3
commit 1c48b8b425
16 changed files with 318 additions and 136 deletions

View File

@@ -15,7 +15,6 @@ namespace SplashEdit.RuntimeCode
Solid = 0x01,
Slope = 0x02,
Stairs = 0x04,
Trigger = 0x08,
NoWalk = 0x10,
}
@@ -84,8 +83,8 @@ namespace SplashEdit.RuntimeCode
foreach (var exporter in exporters)
{
// Dynamic objects are handled by the runtime collision system, skip them
if (!exporter.StaticCollider && exporter.CollisionType != PSXCollisionType.None)
// Dynamic objects use runtime AABB colliders, skip them
if (exporter.CollisionType == PSXCollisionType.Dynamic)
continue;
PSXCollisionType effectiveType = exporter.CollisionType;
@@ -94,7 +93,7 @@ namespace SplashEdit.RuntimeCode
{
if (autoIncludeSolid)
{
effectiveType = PSXCollisionType.Solid;
effectiveType = PSXCollisionType.Static;
autoIncluded++;
}
else
@@ -103,11 +102,8 @@ namespace SplashEdit.RuntimeCode
}
}
// Get the collision mesh (custom or render mesh)
MeshFilter mf = exporter.GetComponent<MeshFilter>();
Mesh collisionMesh = exporter.CustomCollisionMesh != null
? exporter.CustomCollisionMesh
: mf?.sharedMesh;
Mesh collisionMesh = mf?.sharedMesh;
if (collisionMesh == null)
continue;
@@ -133,37 +129,25 @@ namespace SplashEdit.RuntimeCode
// Determine surface flags
byte flags = 0;
if (effectiveType == PSXCollisionType.Trigger)
// Floor-like: normal.y > cosWalkable
float dotUp = normal.y;
if (dotUp > cosWalkable)
{
flags = (byte)PSXSurfaceFlag.Trigger;
flags = (byte)PSXSurfaceFlag.Solid;
if (dotUp < 0.95f && dotUp > cosWalkable)
{
flags |= (byte)PSXSurfaceFlag.Stairs;
}
}
else if (dotUp > 0.0f)
{
flags = (byte)(PSXSurfaceFlag.Solid | PSXSurfaceFlag.Slope);
}
else
{
// Floor-like: normal.y > cosWalkable
// Note: Unity Y is up; PS1 Y is down. We export in Unity space
// and convert to PS1 space during WriteToBinary.
float dotUp = normal.y;
if (dotUp > cosWalkable)
{
flags = (byte)PSXSurfaceFlag.Solid;
// Check if stairs (tagged on exporter or steep-ish)
if (dotUp < 0.95f && dotUp > cosWalkable)
{
flags |= (byte)PSXSurfaceFlag.Stairs;
}
}
else if (dotUp > 0.0f)
{
// Slope too steep to walk on
flags = (byte)(PSXSurfaceFlag.Solid | PSXSurfaceFlag.Slope);
}
else
{
// Wall or ceiling
flags = (byte)PSXSurfaceFlag.Solid;
}
flags = (byte)PSXSurfaceFlag.Solid;
}
_allTriangles.Add(new CollisionTriExport