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 }
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); } } } } } }
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}"); } }