/// <summary> /// Add our wish direction and speed onto our velocity /// </summary> public virtual void Accelerate(Vector3 wishdir, float wishspeed, float speedLimit) { // This gets overridden because some games (CSPort) want to allow dead (observer) players // to be able to move around. // if ( !CanAccelerate() ) // return; if (speedLimit > 0 && wishspeed > speedLimit) { wishspeed = speedLimit; } // See if we are changing direction a bit var currentspeed = Velocity.Dot(wishdir); // Reduce wishspeed by the amount of veer. var addspeed = wishspeed - currentspeed; // If not going to add any speed, done. if (addspeed <= 0) { return; } // Determine amount of acceleration. var accelspeed = Acceleration * Time.Delta * wishspeed * SurfaceFriction; // Cap at addspeed if (accelspeed > addspeed) { accelspeed = addspeed; } Velocity += wishdir * accelspeed; }
private void AddCameraEffects(Camera camera) { var speed = Velocity.Length.LerpInverse(0, 320); var forwardspeed = Velocity.Normal.Dot(camera.Rot.Forward); var left = camera.Rot.Left; var up = camera.Rot.Up; if (GroundEntity != null) { walkBob += Time.Delta * 25.0f * speed; } camera.Pos += up * MathF.Sin(walkBob) * speed * 2; camera.Pos += left * MathF.Sin(walkBob * 0.6f) * speed * 1; lean = lean.LerpTo(Velocity.Dot(camera.Rot.Right) * 0.03f, Time.Delta * 15.0f); var appliedLean = lean; appliedLean += MathF.Sin(walkBob) * speed * 0.2f; camera.Rot *= Rotation.From(0, 0, appliedLean); speed = (speed - 0.7f).Clamp(0, 1) * 3.0f; fov = fov.LerpTo(speed * 20 * MathF.Abs(forwardspeed), Time.Delta * 2.0f); camera.FieldOfView += fov; }
public void Bounce(Vector2f normal, float scale) { float dot = Velocity.Dot(normal); if (dot >= 0f) { return; } if (Bounced != null) { Bounced(this, new EventArgs()); } Velocity -= (1 + scale) * normal * dot; }
private void AddCameraEffects(ref CameraSetup setup) { var speed = Velocity.Length.LerpInverse(0, 320); var forwardspeed = Velocity.Normal.Dot(setup.Rotation.Forward); var left = setup.Rotation.Left; var up = setup.Rotation.Up; if (GroundEntity != null) { walkBob += Time.Delta * 10.0f * speed; } setup.Position += up * MathF.Sin(walkBob) * speed * 2; setup.Position += left * MathF.Sin(walkBob * 0.6f) * speed * 1; // Camera lean lean = lean.LerpTo(Velocity.Dot(setup.Rotation.Right) * 0.01f, Time.Delta * 15.0f); var controller = Controller as WalkController; var wallRun = controller.WallRun; var wallRunLean = wallRun.GetWallJumpDirection(); if (wallRun.IsWallRunning) { Log.Info("wall run lean: " + wallRunLean.ToString()); Log.Info("dot: " + wallRunLean.Dot(setup.Rotation.Right) * 0.01f); lean = lean.LerpTo((wallRunLean.Dot(setup.Rotation.Right) * 0.01f) * 20f, Time.Delta * 10.0f); } var appliedLean = lean; appliedLean += MathF.Sin(walkBob) * speed * 0.2f; setup.Rotation *= Rotation.From(0, 0, appliedLean); speed = (speed - 0.7f).Clamp(0, 1) * 3.0f; fov = fov.LerpTo(speed * 5 * MathF.Abs(forwardspeed), Time.Delta * 2.0f); setup.FieldOfView += fov; }
private void AddCameraEffects(ref CameraSetup setup) { var speed = Velocity.Length.LerpInverse(0, 320); var forwardspeed = Velocity.Normal.Dot(setup.Rotation.Forward); var left = setup.Rotation.Left; var up = setup.Rotation.Up; if (GroundEntity != null) { walkBob += Time.Delta * 25.0f * speed; } setup.Position += up * MathF.Sin(walkBob) * speed * 2; setup.Position += left * MathF.Sin(walkBob * 0.6f) * speed * 1; // Camera lean lean = lean.LerpTo(Velocity.Dot(setup.Rotation.Right) * 0.015f, Time.Delta * 15.0f); var appliedLean = lean; appliedLean += MathF.Sin(walkBob) * speed * 0.2f; setup.Rotation *= Rotation.From(0, 0, appliedLean); speed = (speed - 0.7f).Clamp(0, 1) * 3.0f; fov = fov.LerpTo(speed * 20 * MathF.Abs(forwardspeed), Time.Delta * 2.0f); setup.FieldOfView += fov; // var tx = new Sandbox.UI.PanelTransform(); // tx.AddRotation( 0, 0, lean * -0.1f ); // Hud.CurrentPanel.Style.Transform = tx; // Hud.CurrentPanel.Style.Dirty(); }
void Accelerate(Vector3 wishDir, float wishSpeed, float speedLimit, float acceleration) { if (speedLimit > 0 && wishSpeed > speedLimit) { wishSpeed = speedLimit; } var currentspeed = Velocity.Dot(wishDir); var addspeed = wishSpeed - currentspeed; if (addspeed <= 0) { return; } var accelspeed = acceleration * Time.Delta * wishSpeed; if (accelspeed > addspeed) { accelspeed = addspeed; } Velocity += wishDir * accelspeed; }
public void Accelerate(Vector3 wishDir, float wishSpeed, float speedLimit) { if (speedLimit > 0 && wishSpeed > speedLimit) { wishSpeed = speedLimit; } var currentSpeed = Velocity.Dot(wishDir); var addSpeed = wishSpeed - currentSpeed; if (addSpeed <= 0) { return; } var accelSpeed = Acceleration * Time.Delta * wishSpeed * _surfaceFriction; if (accelSpeed > addSpeed) { accelSpeed = addSpeed; } Velocity += wishDir * accelSpeed; }
void TryPlayerMove() { var timeLeft = Time.Delta; var allFraction = 0.0f; var original_velocity = Velocity; var primal_velocity = Velocity; var numplanes = 0; for (int bumpCount = 0; bumpCount < 4; bumpCount++) { if (Velocity.Length == 0.0f) { break; } // Assume we can move all the way from the current origin to the // end point. var end = Pos + Velocity * timeLeft; var pm = TraceBBox(Pos, end); allFraction += pm.Fraction; // actually covered some distance if (pm.Fraction > DistEpsilon) { // Note: Skipping terrain double check around hack test Pos = pm.EndPos; original_velocity = Velocity; numplanes = 0; } // If we covered the entire distance, we are done // and can return. if (pm.Fraction == 1) { break; // moved the entire distance } // MoveHelper( )->AddToTouched( pm, mv->m_vecVelocity ); bool probablyFloor = pm.Normal.z > GroundNormalZ; // If the plane we hit has a high z component in the normal, then // it's probably a floor if (probablyFloor) { } // If the plane has a zero z component in the normal, then it's a // step or wall if (pm.Normal.z == 0) { } timeLeft -= timeLeft * pm.Fraction; if (numplanes >= planes.Length) { Velocity = Vector3.Zero; break; } planes[numplanes] = pm.Normal; numplanes++; if (numplanes == 1 && GroundEntity == null) { var overbounce = 1.0f; if (!probablyFloor) { overbounce = 1.0f + Bounce * (1.0f - SurfaceFriction); } original_velocity = ClipVelocity(original_velocity, planes[0], overbounce); Velocity = original_velocity; } else { int i = 0; for (i = 0; i < numplanes; i++) { Velocity = ClipVelocity(original_velocity, planes[i], 1); int j = 0; for (j = 0; j < numplanes; j++) { if (j == i) { continue; } // Are we now moving against this plane? if (Velocity.Dot(planes[j]) < 0) { break; // not ok } } if (j == numplanes) // Didn't have to clip, so we're ok { break; } } // Did we go all the way through plane set if (i == numplanes) { if (numplanes != 2) { Velocity = Vector3.Zero; break; } var dir = Vector3.Cross(planes[0], planes[1]).Normal; var d = dir.Dot(Velocity); Velocity = dir * d; } if (Vector3.Dot(Velocity, primal_velocity) <= 0) { Velocity = Vector3.Zero; break; } } } if (allFraction == 0) { Velocity = Vector3.Zero; } // Slam Volumes }
private void TryPlayerMove() { var timeLeft = Time.Delta; var allFraction = 0.0f; var originalVelocity = Velocity; var primalVelocity = Velocity; var numPlanes = 0; for (int bumpCount = 0; bumpCount < 4; bumpCount++) { if (Velocity.Length == 0.0f) { break; } var end = Pos + Velocity * timeLeft; var pm = TraceBBox(Pos, end); allFraction += pm.Fraction; if (pm.Fraction > DistEpsilon) { Pos = pm.EndPos; originalVelocity = Velocity; numPlanes = 0; } if (pm.Fraction == 1) { break; } var probablyFloor = pm.Normal.z > GroundNormalZ; timeLeft -= timeLeft * pm.Fraction; if (numPlanes >= _planes.Length) { Velocity = Vector3.Zero; break; } _planes[numPlanes] = pm.Normal; numPlanes++; if (numPlanes == 1 && GroundEntity == null) { var overbounce = 1.0f; if (!probablyFloor) { overbounce = 1.0f + Bounce * (1.0f - _surfaceFriction); } originalVelocity = ClipVelocity(originalVelocity, _planes[0], overbounce); Velocity = originalVelocity; } else { int i; for (i = 0; i < numPlanes; i++) { Velocity = ClipVelocity(originalVelocity, _planes[i], 1); int j; for (j = 0; j < numPlanes; j++) { if (j == i) { continue; } if (Velocity.Dot(_planes[j]) < 0) { break; } } if (j == numPlanes) { break; } } if (i == numPlanes) { if (numPlanes != 2) { Velocity = Vector3.Zero; break; } var direction = Vector3.Cross(_planes[0], _planes[1]).Normal; var dot = direction.Dot(Velocity); Velocity = direction * dot; } if (Vector3.Dot(Velocity, primalVelocity) <= 0) { Velocity = Vector3.Zero; break; } } } if (allFraction == 0) { Velocity = Vector3.Zero; } }