示例#1
0
        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);
        }
示例#2
0
        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);
                            }
                        }
                    }
                }
            }
        }
示例#3
0
        private void StepMove()
        {
            var vecPos = Pos;
            var vecVel = Velocity;

            //
            // First try walking straight to where they want to go.
            //
            TryPlayerMove();

            //
            // mv now contains where they ended up if they tried to walk straight there.
            // Save those results for use later.
            //
            var vecDownPos = Pos;
            var vecDownVel = Velocity;

            //
            // Reset original values to try some other things.
            //
            Pos      = vecPos;
            Velocity = vecVel;

            // Only step up as high as we have headroom to do so.
            var trace = TraceBBox(Pos, Pos + Vector3.Up * (StepSize + DistEpsilon));

            if (!trace.StartedSolid)
            {
                Pos = trace.EndPos;
            }
            TryPlayerMove();


            trace = TraceBBox(Pos, Pos + Vector3.Down * (StepSize + DistEpsilon * 2));
            if (trace.Normal.z < GroundNormalZ)
            {
                DebugOverlay.Text(vecDownPos, "step down", 2.0f);
                Pos      = vecDownPos;
                Velocity = vecDownVel.WithZ(0);
                // out step height
                return;
            }

            if (!trace.StartedSolid)
            {
                Pos = trace.EndPos;
            }

            var vecUpPos = Pos;

            float flDownDist = (vecDownPos.x - vecPos.x) * (vecDownPos.x - vecPos.x) + (vecDownPos.y - vecPos.y) * (vecDownPos.y - vecPos.y);
            float flUpDist   = (vecUpPos.x - vecPos.x) * (vecUpPos.x - vecPos.x) + (vecUpPos.y - vecPos.y) * (vecUpPos.y - vecPos.y);

            if (flDownDist > flUpDist)
            {
                Pos      = vecDownPos;
                Velocity = vecDownVel;
            }
            else
            {
                // copy z value from slide move
                Velocity = Velocity.WithZ(vecDownVel.z);
            }

            // out step height
        }