Ejemplo n.º 1
0
 public void Box(Entity ent, Color color, float duration = 0.0f)
 {
     if (ent is ModelEntity modelEnt)
     {
         var bbox = modelEnt.OOBBox;
         DebugOverlay.Box(duration, modelEnt.Pos, modelEnt.Rot, bbox.Mins, bbox.Maxs, color);
     }
     else
     {
         DebugOverlay.Box(duration, ent.Pos, ent.Rot, -1, 1, color);
     }
 }
Ejemplo n.º 2
0
        void PivotMove()
        {
            PivotDist -= MoveInput.x * RealTime.Delta * 100 * (PivotDist / 50);
            PivotDist  = PivotDist.Clamp(1, 1000);

            TargetRot = Rotation.From(LookAngles);
            Rot       = Rotation.Slerp(Rot, TargetRot, 40 * RealTime.Delta);

            TargetPos = PivotPos + Rot.Forward * -PivotDist;
            Pos       = TargetPos;

            if (Overlays)
            {
                var scale = Vector3.One * (2 + MathF.Sin(RealTime.Now * 10) * 0.3f);
                DebugOverlay.Box(PivotPos, scale * -1, scale, Color.Green);
            }
        }
Ejemplo n.º 3
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);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public override void Tick()
        {
            ViewOffset = Vector3.Up * EyeHeight;
            UpdateBBox();

            ViewOffset += TraceOffset;

            RestoreGroundPos();

            //Velocity += BaseVelocity * ( 1 + Time.Delta * 0.5f );
            //BaseVelocity = Vector3.Zero;

            //  Rot = Rotation.LookAt( Input.Rot.Forward.WithZ( 0 ), Vector3.Up );

            if (Unstuck.TestAndFix())
            {
                return;
            }

            // Check Stuck
            // Unstuck - or return if stuck

            // Set Ground Entity to null if  falling faster then 250

            // store water level to compare later

            // if not on ground, store fall velocity

            // player->UpdateStepSound( player->m_pSurfaceData, mv->GetAbsOrigin(), mv->m_vecVelocity )


            // RunLadderMode

            Swimming = Player.WaterLevel.Fraction > 0.6f;

            //
            // Start Gravity
            //
            if (!Swimming)
            {
                Velocity -= new Vector3(0, 0, Gravity * 0.5f) * Time.Delta;
                Velocity += new Vector3(0, 0, BaseVelocity.z) * Time.Delta;

                BaseVelocity = BaseVelocity.WithZ(0);
            }


            /*
             * if (player->m_flWaterJumpTime)
             * {
             *  WaterJump();
             *  TryPlayerMove();
             *  // See if we are still in water?
             *  CheckWater();
             *  return;
             * }
             */

            // if ( underwater ) do underwater movement

            if (Input.Pressed(InputButton.Jump))
            {
                CheckJumpButton();
            }

            // Fricion is handled before we add in any base velocity. That way, if we are on a conveyor,
            //  we don't slow when standing still, relative to the conveyor.
            bool bStartOnGround = GroundEntity != null;

            //bool bDropSound = false;
            if (bStartOnGround)
            {
                //if ( Velocity.z < FallSoundZ ) bDropSound = true;

                Velocity = Velocity.WithZ(0);
                //player->m_Local.m_flFallVelocity = 0.0f;

                if (GroundEntity != null)
                {
                    ApplyFriction(GroundFriction * SurfaceFriction);
                }
            }

            //
            // Work out wish velocity.. just take input, rotate it to view, clamp to -1, 1
            //
            WishVelocity = new Vector3(Input.Forward, Input.Left, 0);
            var inSpeed = WishVelocity.Length.Clamp(0, 1);

            WishVelocity *= Input.Rot;

            if (!Swimming)
            {
                WishVelocity = WishVelocity.WithZ(0);
            }

            WishVelocity  = WishVelocity.Normal * inSpeed;
            WishVelocity *= GetWishSpeed();

            Duck.PreTick();

            bool bStayOnGround = false;

            if (Swimming)
            {
                ApplyFriction(1);
                WaterMove();
            }
            else if (GroundEntity != null)
            {
                bStayOnGround = true;
                WalkMove();
            }
            else
            {
                AirMove();
            }

            CategorizePosition(bStayOnGround);

            // FinishGravity
            if (!Swimming)
            {
                Velocity -= new Vector3(0, 0, Gravity * 0.5f) * Time.Delta;
            }


            if (GroundEntity != null)
            {
                Velocity = Velocity.WithZ(0);
            }

            // CheckFalling(); // fall damage etc

            // Land Sound
            // Swim Sounds

            SaveGroundPos();

            if (Debug)
            {
                DebugOverlay.Box(Pos + TraceOffset, mins, maxs, Color.Red);
                DebugOverlay.Box(Pos, mins, maxs, Color.Blue);

                var lineOffset = 0;
                if (Host.IsServer)
                {
                    lineOffset = 10;
                }

                DebugOverlay.ScreenText(lineOffset + 0, $"             Pos: {Pos}");
                DebugOverlay.ScreenText(lineOffset + 1, $"             Vel: {Velocity}");
                DebugOverlay.ScreenText(lineOffset + 2, $"    BaseVelocity: {BaseVelocity}");
                DebugOverlay.ScreenText(lineOffset + 3, $"    GroundEntity: {GroundEntity} [{GroundEntity?.Velocity}]");
                DebugOverlay.ScreenText(lineOffset + 4, $" SurfaceFriction: {SurfaceFriction}");
                DebugOverlay.ScreenText(lineOffset + 5, $"    WishVelocity: {WishVelocity}");
            }
        }