Use RemoveBody+Spawn for ArenaSession pose repositioning
This commit is contained in:
parent
3221ca1d0c
commit
fcf02447ab
1 changed files with 40 additions and 58 deletions
|
|
@ -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;
|
if (c.Alive)
|
||||||
view.PositionZ[lane] = z;
|
{
|
||||||
view.VelocityX[lane] = 0f;
|
SpawnContenderBody(c);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
if (spec.Alive)
|
||||||
view.PositionZ[lane] = z;
|
{
|
||||||
view.VelocityX[lane] = 0f;
|
SpawnSpectatorBody(index, spec);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -318,29 +296,33 @@ 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]);
|
||||||
var spec = s.Grid.Spec;
|
|
||||||
float volume = 8f * spec.HalfWidth * spec.HalfHeight * spec.HalfLength;
|
|
||||||
float density = spec.MassKg / MathF.Max(0.1f, volume);
|
|
||||||
var q = Quaternion.CreateFromAxisAngle(Vector3.UnitY, s.Yaw);
|
|
||||||
ulong stableId = SpectatorStableIdBase + (ulong)s.Id;
|
|
||||||
float spawnY = State.Terrain.SampleHeight(s.X, s.Z) + spec.HalfHeight + 0.15f;
|
|
||||||
s.Y = spawnY;
|
|
||||||
|
|
||||||
var handle = _world.AddBox(
|
|
||||||
stableId,
|
|
||||||
(s.X, spawnY, s.Z),
|
|
||||||
(spec.HalfWidth, spec.HalfHeight, spec.HalfLength),
|
|
||||||
density,
|
|
||||||
(q.X, q.Y, q.Z, q.W),
|
|
||||||
friction: 0.2f,
|
|
||||||
restitution: 0.1f);
|
|
||||||
|
|
||||||
_spectatorBodies[s.Id] = handle;
|
|
||||||
_entityByStableId[stableId] = (false, i);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SpawnSpectatorBody(int index, SpectatorState s)
|
||||||
|
{
|
||||||
|
var spec = s.Grid.Spec;
|
||||||
|
float volume = 8f * spec.HalfWidth * spec.HalfHeight * spec.HalfLength;
|
||||||
|
float density = spec.MassKg / MathF.Max(0.1f, volume);
|
||||||
|
var q = Quaternion.CreateFromAxisAngle(Vector3.UnitY, s.Yaw);
|
||||||
|
ulong stableId = SpectatorStableIdBase + (ulong)s.Id;
|
||||||
|
float spawnY = State.Terrain.SampleHeight(s.X, s.Z) + spec.HalfHeight + 0.15f;
|
||||||
|
s.Y = spawnY;
|
||||||
|
|
||||||
|
var handle = _world.AddBox(
|
||||||
|
stableId,
|
||||||
|
(s.X, spawnY, s.Z),
|
||||||
|
(spec.HalfWidth, spec.HalfHeight, spec.HalfLength),
|
||||||
|
density,
|
||||||
|
(q.X, q.Y, q.Z, q.W),
|
||||||
|
friction: 0.2f,
|
||||||
|
restitution: 0.1f);
|
||||||
|
|
||||||
|
_spectatorBodies[s.Id] = handle;
|
||||||
|
_entityByStableId[stableId] = (false, index);
|
||||||
|
}
|
||||||
|
|
||||||
private void UpdateRingClearance()
|
private void UpdateRingClearance()
|
||||||
{
|
{
|
||||||
Span<RingContact> contacts = stackalloc RingContact[State.Contenders.Count];
|
Span<RingContact> contacts = stackalloc RingContact[State.Contenders.Count];
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue