public virtual bool TestAndFix() { var result = Controller.TraceBBox(Controller.Pos, Controller.Pos); // Not stuck, we cool if (!result.StartedSolid) { StuckTries = 0; return(false); } if (result.StartedSolid) { if (BasePlayerController.Debug) { DebugOverlay.Text(Controller.Pos, $"[stuck in {result.Entity}]", Color.Red); Box(result.Entity, Color.Red); } } // // Client can't jiggle its way out, needs to wait for // server correction to come // if (Host.IsClient) { return(true); } int AttemptsPerTick = 20; for (int i = 0; i < AttemptsPerTick; i++) { var pos = Controller.Pos + Vector3.Random.Normal * (((float)StuckTries) / 2.0f); result = Controller.TraceBBox(pos, pos); if (!result.StartedSolid) { if (BasePlayerController.Debug) { DebugOverlay.Text(Controller.Pos, $"unstuck after {StuckTries} tries ({StuckTries* AttemptsPerTick} tests)", Color.Green, 5.0f); DebugOverlay.Line(pos, Controller.Pos, Color.Green, 5.0f, false); } Controller.Pos = pos; return(false); } else { if (BasePlayerController.Debug) { DebugOverlay.Line(pos, Controller.Pos, Color.Yellow, 0.5f, false); } } } StuckTries++; return(true); }
public override void Update() { var player = Player.Local; if (player == null) { return; } var tr = Trace.Ray(Pos, Pos + Rot.Forward * 4096).UseHitboxes().Run(); // DebugOverlay.Box( tr.EndPos, Vector3.One * -1, Vector3.One, Color.Red ); FieldOfView = FovOverride; Viewer = null; { var lerpTarget = tr.EndPos.Distance(Pos); DoFPoint = lerpTarget; // DoFPoint.LerpTo( lerpTarget, Time.Delta * 10 ); var pos = new Vector3(100, 100); if (Overlays) { DebugOverlay.ScreenText(pos, 10, Color.White, "Focus distance " + DoFPoint.ToString("F"), 0.0f); DebugOverlay.ScreenText(pos, 11, Color.White, "Blur Size " + DoFBlurSize.ToString("F"), 0.0f); } } if (PivotEnabled) { PivotMove(); } else { FreeMove(); } if (Overlays) { var normalRot = Rotation.LookAt(tr.Normal); DebugOverlay.Axis(tr.EndPos, normalRot, 3.0f); if (tr.Entity != null && !tr.Entity.IsWorld) { DebugOverlay.Text(tr.EndPos + Vector3.Up * 20, $"Entity: {tr.Entity} ({tr.Entity.EngineEntityName})\n" + $" Index: {tr.Entity.NetworkIdent}\n" + $"Health: {tr.Entity.Health}", Color.White); if (tr.Entity is ModelEntity modelEnt) { var bbox = modelEnt.OOBBox; DebugOverlay.Box(0, tr.Entity.Pos, tr.Entity.Rot, bbox.Mins, bbox.Maxs, Color.Green); for (int i = 0; i < modelEnt.BoneCount; i++) { var tx = modelEnt.GetBoneTransform(i); var name = modelEnt.GetBoneName(i); var parent = modelEnt.GetBoneParent(i); if (parent > -1) { var ptx = modelEnt.GetBoneTransform(parent); DebugOverlay.Line(tx.Pos, ptx.Pos, Color.White, depthTest: false); } } } } } }