Implement verified Grappler body camera and helpers in VR08

This commit is contained in:
UnixNight committed 2026-11-04 11:27:03 -05:00
1 parent ffea678e90
commit 43806fe862
39 files changed
+2429 -40

No files matched your search

+48 -4
View File
@@ -5,8 +5,8 @@ namespace GamePort.Game;
public readonly record struct PlayerInput(bool Forward, bool Backward, bool Left, bool Right, bool Jump,
bool Rise = false, bool Descend = false, bool StrafeLeft = false, bool StrafeRight = false, bool Fast = false, bool Fire = false,
bool RocketTurn = false, bool RocketRoll = false, bool RocketMouseRise = false);
public enum PlayerPose { Idle, Run, Backpedal, Jump, Fall, Fly, Shoot }
bool RocketTurn = false, bool RocketRoll = false, bool RocketMouseRise = false,bool GrapplerEnter=false);
public enum PlayerPose { Idle, Run, Backpedal, Jump, Fall, Fly, Shoot, Swing }
/// <summary>
/// Walking, airborne steering and jetpack checkpoint. Recovered arithmetic is described in
@@ -35,6 +35,8 @@ public sealed class LabSimulation
private Vector3 noclipEntry;
private float noclipEntryYaw;
private int gadgetMode = -1;
private Vector3? grapplerCameraTarget;
public GrapplerGadget? Grappler {get;private set;}
public bool Noclip { get; private set; }
public bool HasNoclipEntry { get; private set; }
public float NoclipSpeed { get; set; } = 600;
@@ -61,6 +63,7 @@ public sealed class LabSimulation
if (gadgetMode == 0) ReleaseBubble();
if (gadgetMode == 2) Invisible.Release();
if (gadgetMode == 6) Baseball.Release();
if (gadgetMode == 7) Grappler?.Release();
gadgetMode = -1;
if (value == 0)
{
@@ -74,6 +77,11 @@ public sealed class LabSimulation
}
if (value == 2 && !Invisible.Equip(Energy, IgnoresGadgetEnergy)) return;
if (value == 6) Baseball.Equip();
if(value==7)
{
if(Grappler==null)return;
Grappler.Equip();
}
gadgetMode = value;
}
}
@@ -110,6 +118,7 @@ public sealed class LabSimulation
public float TurnRate { get; private set; }
public bool Grounded { get; private set; }
public PlayerPose Pose => Noclip ? Velocity.LengthSquared() > 0 ? PlayerPose.Fly : PlayerPose.Idle
: Grappler?.SwingPose==true ? PlayerPose.Swing
: GadgetMode == 0 ? bubblePose
: pendingImpulse.Y > 0 ? PlayerPose.Jump
: Grounded ? Shooting ? PlayerPose.Shoot : Speed < -1 ? PlayerPose.Backpedal : Speed > 1 ? PlayerPose.Run : PlayerPose.Idle
@@ -128,7 +137,7 @@ public sealed class LabSimulation
public Func<Vector3, Vector3, float, Vector3>? DynamicRootResolver { get; set; }
public Vector3 ActorRoot => Position + Vector3.UnitY * rootHeight;
public Vector3 CameraEye { get; private set; }
public Vector3 CameraTarget => ActorRoot + new Vector3(0, 80 + 1.9f * Baseball.CameraPitch, 0);
public Vector3 CameraTarget => grapplerCameraTarget??ActorRoot + new Vector3(0, 80 + 1.9f * Baseball.CameraPitch, 0);
public Matrix4x4 Model => Matrix4x4.CreateRotationZ(-(TracksBubbleOrientation?Roll:0) * MathF.PI / 180)
* Matrix4x4.CreateRotationX(-(TracksBubbleOrientation?Pitch:0) * MathF.PI / 180) * Matrix4x4.CreateRotationY(-Yaw * MathF.PI / 180)
* Matrix4x4.CreateTranslation(Position - new Vector3(0, modelMinimumY, 0));
@@ -163,6 +172,8 @@ public sealed class LabSimulation
public void Reset()
{
if(gadgetMode==7){GadgetMode=-1;DefaultGadgetRequested?.Invoke();}
Grappler?.Reset();grapplerCameraTarget=null;
if (gadgetMode == 0) { GadgetMode=-1; DefaultGadgetRequested?.Invoke(); }
if (gadgetMode == 2) gadgetMode = -1;
Invisible.Reset();
@@ -282,6 +293,25 @@ public sealed class LabSimulation
AdjustEnergy(-1);ScoreChanged?.Invoke(-1);CancelPoweredFlight();
}
public void EnableGrappler(Mesh world,GrapplerMemory memory)
{
if(LevelCode!="VR08"||originalBody==null)throw new NotSupportedException("Live Grappler requires the VR08 source body");
Grappler=new(world,LevelCode,memory);
Grappler.Detached+=()=>{Velocity=Vector3.Zero;forceFall=true;};
}
private GrapplerMove MoveGrappler(Vector3 desired)
{
var moved=originalBody!.MoveAttached(ActorRoot,desired,InteractionRadius);
if(moved.CallbackPolygon is{} contact)
{
if(contact.StoredNormal.Y<=-.7f)
{if(Velocity.Y>0)Velocity=Velocity with{Y=0};if(extraAirAcceleration>0)extraAirAcceleration=0;}
else {WallHits++;Grappler!.Contact();}
}
return new(moved.Position,Velocity);
}
public void StopForPrimaryFire() => Speed = 0;
public void SetShooting(bool shooting) => Shooting = shooting;
public void AdjustEnergy(float delta) => energy.Adjust(delta, LevelCode, id => EnergySound?.Invoke(id));
@@ -343,6 +373,7 @@ public sealed class LabSimulation
if (enabled == Noclip) return false;
if (enabled)
{
if(gadgetMode==7){GadgetMode=-1;DefaultGadgetRequested?.Invoke();}
if (gadgetMode==0) { GadgetMode=-1; DefaultGadgetRequested?.Invoke(); }
noclipEntry = Position; noclipEntryYaw = Yaw; HasNoclipEntry = true;
}
@@ -426,6 +457,13 @@ public sealed class LabSimulation
}
Baseball.StepCameraInput(input);
StepCamera(); //438BC0/439900 input path owns follow; still provisional geometry/state.
if(Grappler is{Equipped:true} grappler)
{
var state=grappler.StepInput(ActorRoot,new(Pitch,Yaw,Roll),Velocity,input,dt,MoveGrappler);
Position=state.Root-Vector3.UnitY*rootHeight;Pitch=state.Rotation.X;Yaw=state.Rotation.Y;Roll=state.Rotation.Z;Velocity=state.Velocity;
if(state.NewAttachment){jumpState=jumpState with{JumpState=0,EffectRemaining=0};JetpackEffectVisible=false;}
if(state.EndsActiveInput)return;
}
if (movementMode==2)
{
AdjustEnergy(-dt*.5f);
@@ -548,7 +586,7 @@ public sealed class LabSimulation
Grounded = result.Body.Supported;
if (Grounded) forceFall = false;
if (result.Landing != null) Landings++;
if (result.Contact is { StoredNormal.Y: > -.7f }) WallHits++;
if (result.Contact is { StoredNormal.Y: > -.7f }) {WallHits++;Grappler?.Contact();}
Travel += Vector2.Distance(new(before.X, before.Z), new(Position.X, Position.Z));
MaximumRise = Math.Max(MaximumRise, Position.Y - startFloor);
}
@@ -556,6 +594,12 @@ public sealed class LabSimulation
private void StepCamera()
{
const float dt = FixedStepClock.Step;
if(Grappler is{} grappler&&movementMode!=2&&!Noclip)
{
var follow=GrapplerCamera.Follow(grappler.Camera,ActorRoot,new(Pitch,Yaw,Roll),TurnRate,movementMode,CameraEye,dt,cameraRay);
CameraEye=follow.Eye;grapplerCameraTarget=follow.Target;return;
}
grapplerCameraTarget=null;
var desired = DesiredEye();
var delta = (desired.Eye - CameraEye) * new Vector3(1.6f, 1.2f, 1.6f) * desired.Gain * dt;
CameraEye = cameraRay == null ? collision.ClipCamera(CameraTarget, CameraEye + delta) : CameraEye + delta;