Пример #1
0
    public override void BuildInput(ClientInput input)
    {
        base.BuildInput(input);

        var player = Player.Local;

        if (player == null)
        {
            return;
        }

        if ((Math.Abs(input.AnalogLook.pitch) + Math.Abs(input.AnalogLook.yaw)) > 0.0f)
        {
            if (!orbitEnabled)
            {
                orbitAngles = Rot.Angles();
                orbitAngles = orbitAngles.Normal;

                orbitYawRot   = Rotation.From(0.0f, orbitAngles.yaw, 0.0f);
                orbitPitchRot = Rotation.From(orbitAngles.pitch, 0.0f, 0.0f);
            }

            orbitEnabled = true;
            orbitTimer   = Time.Now + OrbitCooldown;

            orbitAngles.yaw   += input.AnalogLook.yaw;
            orbitAngles.pitch += input.AnalogLook.pitch;
            orbitAngles        = orbitAngles.Normal;
            orbitAngles.pitch  = orbitAngles.pitch.Clamp(MinOrbitPitch, MaxOrbitPitch);
        }

        input.ViewAngles = orbitAngles.WithYaw(orbitAngles.yaw - player.WorldRot.Yaw());
        input.ViewAngles = input.ViewAngles.Normal;
    }
Пример #2
0
        public override void Spawn()
        {
            base.Spawn();

            RotationA = Rot.Angles();

            var degrees = RotationDegrees - Lip;

            if (SpawnFlags.Has(Flags.RotateBackwards))
            {
                degrees *= -1.0f;
            }

            if (SpawnFlags.Has(Flags.Pitch))
            {
                RotationB = RotationA + new Angles(degrees, 0, 0);
            }
            else if (SpawnFlags.Has(Flags.Roll))
            {
                RotationB = RotationA + new Angles(0, 0, degrees);
            }
            else
            {
                RotationB = RotationA + new Angles(0, degrees, 0);
            }
        }
Пример #3
0
    public void OnPostPhysicsStep(float dt)
    {
        if (!PhysicsBody.IsValid())
        {
            return;
        }

        var body      = PhysicsBody;
        var transform = Transform;

        body.LinearDrag     = 1.0f;
        body.AngularDrag    = 1.0f;
        body.LinearDamping  = 4.0f;
        body.AngularDamping = 4.0f;

        var yawRot            = Rotation.From(new Angles(0, Rot.Angles().yaw, 0));
        var worldMovement     = yawRot * currentInput.movement;
        var velocityDirection = body.Velocity.WithZ(0);
        var velocityMagnitude = velocityDirection.Length;

        velocityDirection = velocityDirection.Normal;

        var velocityScale = (velocityMagnitude / leanMaxVelocity).Clamp(0, 1);
        var leanDirection = worldMovement.LengthSquared == 0.0f
                        ? -velocityScale * velocityDirection
                        : worldMovement;

        var targetUp  = (Vector3.Up + leanDirection * leanWeight * velocityScale).Normal;
        var currentUp = transform.NormalToWorld(Vector3.Up);
        var alignment = Math.Max(Vector3.Dot(targetUp, currentUp), 0);

        bool hasCollision = false;
        bool isGrounded   = false;

        if (!hasCollision || isGrounded)
        {
            var hoverForce    = isGrounded && currentInput.throttle <= 0 ? Vector3.Zero : -1 * transform.NormalToWorld(Vector3.Up) * -800.0f;
            var movementForce = isGrounded ? Vector3.Zero : worldMovement * movementAcceleration;
            var altitudeForce = transform.NormalToWorld(Vector3.Up) * currentInput.throttle * altitudeAcceleration;
            var totalForce    = hoverForce + movementForce + altitudeForce;
            body.ApplyForce((totalForce * alignment) * body.Mass);
        }

        if (!hasCollision && !isGrounded)
        {
            var spinTorque       = Transform.NormalToWorld(new Vector3(0, 0, currentInput.yaw * yawSpeed));
            var uprightTorque    = Vector3.Cross(currentUp, targetUp) * uprightSpeed;
            var uprightAlignment = alignment < uprightDot ? 0 : alignment;
            var totalTorque      = spinTorque * alignment + uprightTorque * uprightAlignment;
            body.ApplyTorque((totalTorque * alignment) * body.Mass);
        }
    }
Пример #4
0
        public override void Activated()
        {
            base.Activated();

            FocusPoint  = CurrentView.Position - GetViewOffset();
            FieldOfView = 70;

            LookAngles  = Rot.Angles();
            FovOverride = 80;

            Pos = CurrentView.Position;
            Rot = CurrentView.Rotation;
        }
Пример #5
0
        public override void UpdateState(bool open)
        {
            var rot = open ? RotationB : RotationA;

            if (Speed <= 0)
            {
                Speed = 0.1f;
            }

            var dfference = (Rot.Angles() - rot).Normal;
            var distance  = dfference.Length;
            var seconds   = distance / Speed;

            _ = DoMove(Rotation.From(rot), seconds);
        }
Пример #6
0
        public override void Activated()
        {
            base.Activated();

            Host.AssertClient();

            LookDistance = Cookie.Get("LookDistance", LookDistance);
            SpectMode    = Cookie.Get("Mode", SpectMode);

            LookAngles  = Rot.Angles();
            FovOverride = 80;

            Pos = CurrentView.Position;
            Rot = CurrentView.Rotation;

            // Update new positions also.
            //Update();
        }
Пример #7
0
        /// <summary>
        /// On the camera becoming activated, snap to the current view position
        /// </summary>
        public override void Activated()
        {
            base.Activated();

            TargetPos = Camera.LastPos;
            TargetRot = Camera.LastRot;

            Pos         = TargetPos;
            Rot         = TargetRot;
            LookAngles  = Rot.Angles();
            FovOverride = 80;

            DoFPoint    = 0.0f;
            DoFBlurSize = 20.0f;


            if (Overlays)
            {
                var pos      = new Vector3(100, 100);
                var duration = 4.0f;

                DebugOverlay.ScreenText(pos, 0, Color.White, "  .                        ", duration);
                DebugOverlay.ScreenText(pos, 1, Color.White, ",-| ,-. .  , ,-. ,-. ,-,-. ", duration);
                DebugOverlay.ScreenText(pos, 2, Color.White, "| | |-' | /  |   ,-| | | | ", duration);
                DebugOverlay.ScreenText(pos, 3, Color.White, "`-^ `-' `'   `-' `-^ ' ' ' ", duration);

                DebugOverlay.ScreenText(pos, 5, Color.White, "  Free:  WSAD, Run/Crouch for speed", duration);
                DebugOverlay.ScreenText(pos, 6, Color.White, " Pivot:  Hold Walk (Default Alt) - forward + back to zoom in/out", duration);
                DebugOverlay.ScreenText(pos, 8, Color.White, "Reload:  Toggle Overlays", duration);
            }

            //
            // Set the devcamera class on the HUD. It's up to the HUD what it does with it.
            //
            Hud.Current?.RootPanel?.SetClass("devcamera", true);
        }