Use RemoveBody+Spawn for ArenaSession pose repositioning

This commit is contained in:
Meta Vens 2026-12-04 15:15:44 +01:00
commit fcf02447ab

View file

@ -63,41 +63,31 @@ namespace RustToDust.Ymir
return; return;
} }
var c = State.Contenders[contenderId]; var c = State.Contenders[contenderId];
float y = State.Terrain.SampleHeight(x, z) + c.Grid.Spec.HalfHeight + 0.15f;
c.X = x; c.X = x;
c.Y = y;
c.Z = z; c.Z = z;
if (yaw.HasValue) c.Yaw = yaw.Value; if (yaw.HasValue) c.Yaw = yaw.Value;
if (_contenderBodies.TryGetValue(contenderId, out var handle)) if (_contenderBodies.TryGetValue(contenderId, out var oldHandle))
{ {
var view = _world.View; _world.RemoveBody(oldHandle);
int lane = handle.Lane; _contenderBodies.Remove(contenderId);
view.PositionX[lane] = x;
view.PositionY[lane] = y;
view.PositionZ[lane] = z;
view.VelocityX[lane] = 0f;
view.VelocityY[lane] = 0f;
view.VelocityZ[lane] = 0f;
if (yaw.HasValue)
{
var q = Quaternion.CreateFromAxisAngle(Vector3.UnitY, yaw.Value);
view.RotationX[lane] = q.X;
view.RotationY[lane] = q.Y;
view.RotationZ[lane] = q.Z;
view.RotationW[lane] = q.W;
} }
if (c.Alive)
{
SpawnContenderBody(c);
} }
} }
public void SetSpectatorPose(int spectatorId, float x, float z, float? yaw = null) public void SetSpectatorPose(int spectatorId, float x, float z, float? yaw = null)
{ {
SpectatorState? spec = null; SpectatorState? spec = null;
int index = -1;
for (int i = 0; i < State.Spectators.Spectators.Count; i++) for (int i = 0; i < State.Spectators.Spectators.Count; i++)
{ {
if (State.Spectators.Spectators[i].Id == spectatorId) if (State.Spectators.Spectators[i].Id == spectatorId)
{ {
spec = State.Spectators.Spectators[i]; spec = State.Spectators.Spectators[i];
index = i;
break; break;
} }
} }
@ -106,30 +96,18 @@ namespace RustToDust.Ymir
return; return;
} }
float y = State.Terrain.SampleHeight(x, z) + spec.Grid.Spec.HalfHeight + 0.15f;
spec.X = x; spec.X = x;
spec.Y = y;
spec.Z = z; spec.Z = z;
if (yaw.HasValue) spec.Yaw = yaw.Value; if (yaw.HasValue) spec.Yaw = yaw.Value;
if (_spectatorBodies.TryGetValue(spectatorId, out var handle)) if (_spectatorBodies.TryGetValue(spectatorId, out var oldHandle))
{ {
var view = _world.View; _world.RemoveBody(oldHandle);
int lane = handle.Lane; _spectatorBodies.Remove(spectatorId);
view.PositionX[lane] = x;
view.PositionY[lane] = y;
view.PositionZ[lane] = z;
view.VelocityX[lane] = 0f;
view.VelocityY[lane] = 0f;
view.VelocityZ[lane] = 0f;
if (yaw.HasValue)
{
var q = Quaternion.CreateFromAxisAngle(Vector3.UnitY, yaw.Value);
view.RotationX[lane] = q.X;
view.RotationY[lane] = q.Y;
view.RotationZ[lane] = q.Z;
view.RotationW[lane] = q.W;
} }
if (spec.Alive)
{
SpawnSpectatorBody(index, spec);
} }
} }
@ -318,7 +296,12 @@ namespace RustToDust.Ymir
{ {
for (int i = 0; i < State.Spectators.Spectators.Count; i++) for (int i = 0; i < State.Spectators.Spectators.Count; i++)
{ {
var s = State.Spectators.Spectators[i]; SpawnSpectatorBody(i, State.Spectators.Spectators[i]);
}
}
private void SpawnSpectatorBody(int index, SpectatorState s)
{
var spec = s.Grid.Spec; var spec = s.Grid.Spec;
float volume = 8f * spec.HalfWidth * spec.HalfHeight * spec.HalfLength; float volume = 8f * spec.HalfWidth * spec.HalfHeight * spec.HalfLength;
float density = spec.MassKg / MathF.Max(0.1f, volume); float density = spec.MassKg / MathF.Max(0.1f, volume);
@ -337,8 +320,7 @@ namespace RustToDust.Ymir
restitution: 0.1f); restitution: 0.1f);
_spectatorBodies[s.Id] = handle; _spectatorBodies[s.Id] = handle;
_entityByStableId[stableId] = (false, i); _entityByStableId[stableId] = (false, index);
}
} }
private void UpdateRingClearance() private void UpdateRingClearance()