Ejemplo n.º 1
0
    void WalkMove()
    {
        var wishdir   = WishVelocity.Normal;
        var wishspeed = WishVelocity.Length;

        WishVelocity = WishVelocity.WithZ(0);
        WishVelocity = WishVelocity.Normal * wishspeed;

        Velocity = Velocity.WithZ(0);
        Accelerate(wishdir, wishspeed, 0, Acceleration);
        Velocity = Velocity.WithZ(0);

        //   Player.SetAnimParam( "forward", Input.Forward );
        //   Player.SetAnimParam( "sideward", Input.Right );
        //   Player.SetAnimParam( "wishspeed", wishspeed );
        //    Player.SetAnimParam( "walkspeed_scale", 2.0f / 190.0f );
        //   Player.SetAnimParam( "runspeed_scale", 2.0f / 320.0f );

        //  DebugOverlay.Text( 0, Pos + Vector3.Up * 100, $"forward: {Input.Forward}\nsideward: {Input.Right}" );

        // Add in any base velocity to the current velocity.
        Velocity += BaseVelocity;

        try
        {
            if (Velocity.Length < 1.0f)
            {
                Velocity = Vector3.Zero;
                return;
            }

            // first try just moving to the destination
            var dest = (Position + Velocity * Time.Delta).WithZ(Position.z);

            var pm = TraceBBox(Position, dest);

            if (pm.Fraction == 1)
            {
                Position = pm.EndPos;
                StayOnGround();
                return;
            }

            StepMove();
        }
        finally
        {
            // Now pull the base velocity back out.   Base velocity is set if you are on a moving object, like a conveyor (or maybe another monster?)
            Velocity -= BaseVelocity;
        }

        StayOnGround();
    }
Ejemplo n.º 2
0
        private void WalkMove()
        {
            var wishdir   = WishVelocity.Normal;
            var wishspeed = WishVelocity.Length;

            WishVelocity = WishVelocity.WithZ(0);
            WishVelocity = WishVelocity.Normal * wishspeed;

            Velocity = Velocity.WithZ(0);

            Accelerate(wishdir, wishspeed, 0);

            Velocity  = Velocity.WithZ(0);
            Velocity += BaseVelocity;

            try
            {
                if (Velocity.Length < 1.0f)
                {
                    Velocity = Vector3.Zero;
                    return;
                }

                var dest = (Pos + Velocity * Time.Delta).WithZ(Pos.z);
                var pm   = TraceBBox(Pos, dest);

                if (pm.Fraction == 1)
                {
                    Pos = pm.EndPos;
                    StayOnGround();
                    return;
                }

                StepMove();
            }
            finally
            {
                Velocity -= BaseVelocity;
            }

            StayOnGround();
        }
Ejemplo n.º 3
0
        public override void Simulate()
        {
            EyePosLocal = Vector3.Up * (EyeHeight * Pawn.Scale);
            UpdateBBox();

            EyePosLocal += TraceOffset;
            EyeRot       = Input.Rotation;

            RestoreGroundPos();

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

            //Rot = Rotation.LookAt( Input.Rotation.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

            CheckLadder();
            Swimming = Pawn.WaterLevel.Fraction > 0.6f;

            //
            // Start Gravity
            //
            if (!Swimming && !IsTouchingLadder)
            {
                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 (Client != null && AutoJump ? Input.Down(InputButton.Jump) : 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 = Client != null ? new Vector3(Input.Forward, Input.Left, 0) : Vector3.Zero;
            var inSpeed = WishVelocity.Length.Clamp(0, 1);

            if (Client != null)
            {
                WishVelocity *= Input.Rotation;
            }

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

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

            Duck.PreTick();

            bool bStayOnGround = false;

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

            CategorizePosition(bStayOnGround);

            // FinishGravity
            if (!Swimming && !IsTouchingLadder)
            {
                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(Position + TraceOffset, mins, maxs, Color.Red);
                DebugOverlay.Box(Position, mins, maxs, Color.Blue);

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

                DebugOverlay.ScreenText(lineOffset + 0, $"        Position: {Position}");
                DebugOverlay.ScreenText(lineOffset + 1, $"        Velocity: {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}");
            }
        }