Exemple #1
0
        public void Move(Vector3 delta, int a = 0)
        {
            if (a > 1)
            {
                return;
            }

            var len       = delta.Length;
            var targetPos = Pos + delta;
            var tr        = Trace.Ray(Pos, targetPos).WorldOnly().Size(Size).Run();

            if (tr.StartedSolid)
            {
                Pos = targetPos;
            }
            else if (tr.Hit)
            {
                Pos = tr.EndPos + tr.Normal;

                // subtract the normal from our velocity
                Velocity = Velocity.SubtractDirection(tr.Normal * (1.0f + Bounce));

                delta = Velocity.Normal * delta.Length * (1.0f - tr.Fraction);

                Move(delta, ++a);
            }
            else
            {
                Pos = tr.EndPos;
            }
        }
Exemple #2
0
        public override void Update()
        {
            var player = Local.Pawn as Player;

            if (player == null)
            {
                return;
            }

            // lerp the focus point
            FocusPoint = Vector3.Lerp(FocusPoint, GetSpectatePoint(), Time.Delta * 50.0f);

            Vector3 targetPos = FocusPoint + GetViewOffset();

            // Col: cast ray from focus point to target
            var traceResult = Trace.Ray(FocusPoint, targetPos).Radius(boxSize).WorldOnly().Run();

            targetPos = traceResult.EndPos;             // Shift camera away from wall

            // Set positions
            Pos = targetPos;
            Rot = player.EyeRot;

            FieldOfView = ExtractionConfig.FieldOfView;
            Viewer      = null;
        }
Exemple #3
0
        public override void BuildInput(ClientInput input)
        {
            MoveInput = input.AnalogMove;

            MoveSpeed = 1;
            if (input.Down(InputButton.Run))
            {
                MoveSpeed = 5;
            }
            if (input.Down(InputButton.Duck))
            {
                MoveSpeed = 0.2f;
            }

            if (input.Pressed(InputButton.Walk))
            {
                var tr = Trace.Ray(Pos, Pos + Rot.Forward * 4096).Run();
                PivotPos  = tr.EndPos;
                PivotDist = Vector3.DistanceBetween(tr.EndPos, Pos);
            }

            if (input.Down(InputButton.Use))
            {
                DoFBlurSize = Math.Clamp(DoFBlurSize + (Time.Delta * 3.0f), 0.0f, 100.0f);
            }

            if (input.Down(InputButton.Menu))
            {
                DoFBlurSize = Math.Clamp(DoFBlurSize - (Time.Delta * 3.0f), 0.0f, 100.0f);
            }


            if (input.Down(InputButton.Attack2))
            {
                FovOverride     += input.AnalogLook.pitch * (FovOverride / 30.0f);
                FovOverride      = FovOverride.Clamp(5, 150);
                input.AnalogLook = default;
            }

            LookAngles     += input.AnalogLook * (FovOverride / 80.0f);
            LookAngles.roll = 0;

            PivotEnabled = input.Down(InputButton.Walk);

            if (input.Pressed(InputButton.Reload))
            {
                Overlays = !Overlays;
            }

            input.Clear();
            input.StopProcessing = true;
        }
        public override void Update()
        {
            var player = Player.Local;

            if (player == null)
            {
                return;
            }

            Pos = player.WorldPos;
            Vector3 targetPos;

            if (thirdperson_orbit)
            {
                Pos += Vector3.Up * 40;
                Rot  = Rotation.From(orbitAngles);

                targetPos = Pos + Rot.Backward * orbitDistance;
            }
            else
            {
                Pos  = player.WorldPos;
                Pos += Vector3.Up * 70;
                Pos += player.EyeRot.Right * 30;
                Rot  = Rotation.FromAxis(Vector3.Up, 4) * player.EyeRot;

                const float distance = 130;
                targetPos = Pos + player.EyeRot.Forward * -distance;
            }

            if (thirdperson_collision)
            {
                var tr = Trace.Ray(Pos, targetPos)
                         .Ignore(player)
                         .Radius(8)
                         .Run();

                Pos = tr.EndPos;
            }
            else
            {
                Pos = targetPos;
            }

            FieldOfView = 70;

            Viewer = null;
        }
Exemple #5
0
        /// <summary>
        /// Does a trace from start to end, does bullet impact effects. Coded as an IEnumerable so you can return multiple
        /// hits, like if you're going through layers or ricocet'ing or something.
        /// </summary>
        public virtual IEnumerable <TraceResult> TraceBullet(Vector3 start, Vector3 end, float radius = 2.0f)
        {
            bool InWater = Physics.TestPointContents(start, CollisionLayer.Water);

            var tr = Trace.Ray(start, end)
                     .UseHitboxes()
                     .HitLayer(CollisionLayer.Water, !InWater)
                     .Ignore(Owner)
                     .Ignore(this)
                     .Size(radius)
                     .Run();

            yield return(tr);

            //
            // Another trace, bullet going through thin material, penetrating water surface?
            //
        }
        /// <summary>
        /// Find a usable entity for this player to use
        /// </summary>
        protected virtual Entity FindUsable()
        {
            var tr = Trace.Ray(EyePos, EyePos + EyeRot.Forward * 80)
                     .Radius(2)
                     .Ignore(this)
                     .Run();

            if (tr.Entity == null)
            {
                return(null);
            }
            if (tr.Entity is not IUse use)
            {
                return(null);
            }
            if (!use.IsUsable(this))
            {
                return(null);
            }

            return(tr.Entity);
        }
        /// <summary>
        /// Traces the bbox and returns the trace result.
        /// LiftFeet will move the start position up by this amount, while keeping the top of the bbox at the same
        /// position. This is good when tracing down because you won't be tracing through the ceiling above.
        /// </summary>
        public virtual TraceResult TraceBBox(Vector3 start, Vector3 end, Vector3 mins, Vector3 maxs, float liftFeet = 0.0f)
        {
            if (liftFeet > 0)
            {
                start += Vector3.Up * liftFeet;
                maxs   = maxs.WithZ(maxs.z - liftFeet);
            }

            //pFilter->m_attr.SetCollisionGroup( collisionGroup ); // COLLISION_GROUP_PLAYER_MOVEMENT
            // pFilter->m_attr.SetHitSolidRequiresGenerateContacts( true );

            var tr = Trace.Ray(start + TraceOffset, end + TraceOffset)
                     .Size(mins, maxs)
                     .HitLayer(CollisionLayer.All, false)
                     .HitLayer(CollisionLayer.Solid, true)
                     .HitLayer(CollisionLayer.GRATE, true)
                     .HitLayer(CollisionLayer.PLAYER_CLIP, true)
                     .Ignore(Player)
                     .Run();

            tr.EndPos -= TraceOffset;
            return(tr);
        }
Exemple #8
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);
                            }
                        }
                    }
                }
            }
        }