void UpdateCurrentTool(Player owner) { var toolName = owner.GetUserString("tool_current", "tool_boxgun"); if (toolName == null) { return; } DebugOverlay.ScreenText(0, $"tool_current: {toolName}"); DebugOverlay.ScreenText(1, $" CurrentTool: {CurrentTool}"); // Already the right tool if (CurrentTool != null && CurrentTool.Parent == this && CurrentTool.Owner == owner && CurrentTool.ClassInfo.IsNamed(toolName)) { return; } if (CurrentTool != null) { CurrentTool?.Deactivate(); CurrentTool = null; } CurrentTool = Library.Create <BaseTool>(toolName, false); if (CurrentTool != null) { CurrentTool.Parent = this; CurrentTool.Owner = owner; CurrentTool.Activate(); } }
void WriteDebugInfo() { BBox hull = GetHull(); DebugOverlay.Box(Position + TraceOffset, hull.Mins, hull.Maxs, Color.Red); DebugOverlay.Box(Position, hull.Mins, hull.Maxs, Color.Blue); var lineOffset = Host.IsServer ? 10 : 0; DebugOverlay.ScreenText(lineOffset + 0, $" Pos: {Position}"); DebugOverlay.ScreenText(lineOffset + 1, $" Vel: {Velocity} ({Velocity.Length:n0})"); DebugOverlay.ScreenText(lineOffset + 2, $" WishVelocity: {WishVelocity}"); DebugOverlay.ScreenText(lineOffset + 3, $" BaseVelocity: {BaseVelocity}"); DebugOverlay.ScreenText(lineOffset + 4, $" Rotation: {Rotation.Angles().pitch:n2},{Rotation.Angles().yaw:n2},{Rotation.Angles().roll:n2}"); }
protected override void Update(GameTime gameTime) { #region Input. if (!IsActive) { return; } if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { this.Exit(); } #endregion ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// // Let's draw some stuff... // Draw code can be called from anywhere in the application - // even in separate threads! Use it for AI, Physics, // Gameplay, Graphics, etc. // Lines. for (int i = 0; i < 25; ++i) { DebugOverlay.Line(new Vector3(.5f * i, 5, 5), new Vector3(.5f * i, 5, -5), Color.Tomato); DebugOverlay.Line(new Vector3(.5f * i, 3, 5), new Vector3(.5f * i, 3, -5), Color.Violet); DebugOverlay.Line(new Vector3(.5f * i, 1, 5), new Vector3(.5f * i, 1, -5), Color.SeaGreen); } // Points. float radius = 4; for (int i = 0; i < 360; i += 2) { float rads = i * MathHelper.Pi / 180; DebugOverlay.Point(new Vector3( (float)Math.Cos(rads) * radius, -5, (float)Math.Sin(rads) * radius), Color.Black); } // Spheres. DebugOverlay.Sphere(new Vector3(-10, 0, 5), 3, Color.Brown); DebugOverlay.Sphere(new Vector3(-5, 0, 5), 2, Color.DarkGreen); DebugOverlay.Sphere(new Vector3(-2, 0, 5), 1, Color.Crimson); DebugOverlay.Sphere(new Vector3(-.5f, 0, 5), .5f, Color.DarkSalmon); // Bounding box. DebugOverlay.BoundingBox(new BoundingBox(new Vector3(-10, 0, -10), new Vector3(-5, 5, -5)), Color.RoyalBlue); // Screen text. DebugOverlay.ScreenText("FPS: " + mFps.FramesPerSecond, new Vector2(5, 7), Color.DimGray); DebugOverlay.ScreenText("FPS: " + mFps.FramesPerSecond, new Vector2(7, 5), Color.White); // Arrows. DebugOverlay.Arrow(Vector3.Zero, Vector3.UnitX * 10, 1, Color.Red); DebugOverlay.Arrow(Vector3.Zero, Vector3.UnitY * 10, 1, Color.Green); DebugOverlay.Arrow(Vector3.Zero, Vector3.UnitZ * 10, 1, Color.Blue); ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// #region Update. mCamera.Update((float)gameTime.ElapsedGameTime.TotalSeconds); mFps.Tick(); base.Update(gameTime); #endregion }
public override void Simulate() { // Do fall damage stufftw if (Velocity.z < 0) { takeFallDamage = true; previousZVelocity = Velocity.z; } else if (takeFallDamage && Velocity.z == 0) { takeFallDamage = false; TakeDmg(); } 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 (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 = new Vector3(Input.Forward, Input.Left, 0); var inSpeed = WishVelocity.Length.Clamp(0, 1); WishVelocity *= Input.Rotation; if (!Swimming && !IsTouchingLadder) { WishVelocity = WishVelocity.WithZ(0); } WishVelocity = WishVelocity.Normal * inSpeed; WishVelocity *= GetWishSpeed(); Duck.PreTick(); bool bStayOnGround = false; if (AttachedBalloons > 0) { ClearGroundEntity(); Velocity = Velocity.WithZ(1 * AttachedBalloons * BalloonVelocity); AirMove(); } else 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}"); } }
public void OnPrePhysicsStep() { if (!IsServer) { return; } var selfBody = PhysicsBody; if (!selfBody.IsValid()) { return; } var body = selfBody.SelfOrParent; if (!body.IsValid()) { return; } var dt = Time.Delta; body.DragEnabled = false; var rotation = selfBody.Rotation; accelerateDirection = currentInput.throttle.Clamp(-1, 1) * (1.0f - currentInput.breaking); TurnDirection = TurnDirection.LerpTo(currentInput.turning.Clamp(-1, 1), 1.0f - MathF.Pow(0.001f, dt)); airRoll = airRoll.LerpTo(currentInput.roll.Clamp(-1, 1), 1.0f - MathF.Pow(0.0001f, dt)); airTilt = airTilt.LerpTo(currentInput.tilt.Clamp(-1, 1), 1.0f - MathF.Pow(0.0001f, dt)); float targetTilt = 0; float targetLean = 0; var localVelocity = rotation.Inverse * body.Velocity; if (backWheelsOnGround || frontWheelsOnGround) { var forwardSpeed = MathF.Abs(localVelocity.x); var speedFraction = MathF.Min(forwardSpeed / 500.0f, 1); targetTilt = accelerateDirection.Clamp(-1.0f, 1.0f); targetLean = speedFraction * TurnDirection; } AccelerationTilt = AccelerationTilt.LerpTo(targetTilt, 1.0f - MathF.Pow(0.01f, dt)); TurnLean = TurnLean.LerpTo(targetLean, 1.0f - MathF.Pow(0.01f, dt)); if (backWheelsOnGround) { var forwardSpeed = MathF.Abs(localVelocity.x); var speedFactor = 1.0f - (forwardSpeed / 5000.0f).Clamp(0.0f, 1.0f); var acceleration = speedFactor * (accelerateDirection < 0.0f ? car_accelspeed * 0.5f : car_accelspeed) * accelerateDirection * dt; var impulse = rotation * new Vector3(acceleration, 0, 0); body.Velocity += impulse; } RaycastWheels(rotation, true, out frontWheelsOnGround, out backWheelsOnGround, dt); var onGround = frontWheelsOnGround || backWheelsOnGround; var fullyGrounded = (frontWheelsOnGround && backWheelsOnGround); Grounded = onGround; if (fullyGrounded) { body.Velocity += Map.Physics.Gravity * dt; } body.GravityScale = fullyGrounded ? 0 : 1; bool canAirControl = false; var v = rotation * localVelocity.WithZ(0); var vDelta = MathF.Pow((v.Length / 1000.0f).Clamp(0, 1), 5.0f).Clamp(0, 1); if (vDelta < 0.01f) { vDelta = 0; } if (debug_car) { DebugOverlay.Line(body.MassCenter, body.MassCenter + rotation.Forward.Normal * 100, Color.White, 0, false); DebugOverlay.Line(body.MassCenter, body.MassCenter + v.Normal * 100, Color.Green, 0, false); } var angle = (rotation.Forward.Normal * MathF.Sign(localVelocity.x)).Normal.Dot(v.Normal).Clamp(0.0f, 1.0f); angle = angle.LerpTo(1.0f, 1.0f - vDelta); grip = grip.LerpTo(angle, 1.0f - MathF.Pow(0.001f, dt)); if (debug_car) { DebugOverlay.ScreenText(new Vector2(200, 200), $"{grip}"); } var angularDamping = 0.0f; angularDamping = angularDamping.LerpTo(5.0f, grip); body.LinearDamping = 0.0f; body.AngularDamping = fullyGrounded ? angularDamping : 0.5f; if (onGround) { localVelocity = rotation.Inverse * body.Velocity; WheelSpeed = localVelocity.x; var turnAmount = frontWheelsOnGround ? (MathF.Sign(localVelocity.x) * 25.0f * CalculateTurnFactor(TurnDirection, MathF.Abs(localVelocity.x)) * dt) : 0.0f; body.AngularVelocity += rotation * new Vector3(0, 0, turnAmount); airRoll = 0; airTilt = 0; var forwardGrip = 0.1f; forwardGrip = forwardGrip.LerpTo(0.9f, currentInput.breaking); body.Velocity = VelocityDamping(Velocity, rotation, new Vector3(forwardGrip, grip, 0), dt); } else { var s = selfBody.Position + (rotation * selfBody.LocalMassCenter); var tr = Trace.Ray(s, s + rotation.Down * 50) .Ignore(this) .Run(); if (debug_car) { DebugOverlay.Line(tr.StartPosition, tr.EndPosition, tr.Hit ? Color.Red : Color.Green); } canAirControl = !tr.Hit; } if (canAirControl && (airRoll != 0 || airTilt != 0)) { var offset = 50 * Scale; var s = selfBody.Position + (rotation * selfBody.LocalMassCenter) + (rotation.Right * airRoll * offset) + (rotation.Down * (10 * Scale)); var tr = Trace.Ray(s, s + rotation.Up * (25 * Scale)) .Ignore(this) .Run(); if (debug_car) { DebugOverlay.Line(tr.StartPosition, tr.EndPosition); } bool dampen = false; if (currentInput.roll.Clamp(-1, 1) != 0) { var force = tr.Hit ? 400.0f : 100.0f; var roll = tr.Hit ? currentInput.roll.Clamp(-1, 1) : airRoll; body.ApplyForceAt(selfBody.MassCenter + rotation.Left * (offset * roll), (rotation.Down * roll) * (roll * (body.Mass * force))); if (debug_car) { DebugOverlay.Sphere(selfBody.MassCenter + rotation.Left * (offset * roll), 8, Color.Red); } dampen = true; } if (!tr.Hit && currentInput.tilt.Clamp(-1, 1) != 0) { var force = 200.0f; body.ApplyForceAt(selfBody.MassCenter + rotation.Forward * (offset * airTilt), (rotation.Down * airTilt) * (airTilt * (body.Mass * force))); if (debug_car) { DebugOverlay.Sphere(selfBody.MassCenter + rotation.Forward * (offset * airTilt), 8, Color.Green); } dampen = true; } if (dampen) { body.AngularVelocity = VelocityDamping(body.AngularVelocity, rotation, 0.95f, dt); } } localVelocity = rotation.Inverse * body.Velocity; MovementSpeed = localVelocity.x; }
private void DrawDebugShit() { DebugOverlay.ScreenText(new Vector2(100, 100), $"Current trigger state: {CurrentTriggerType}"); }
public static void DebugText(this object any, int line = 0, int duration = 0) { DebugOverlay.ScreenText(line, any.ToString(), duration); }