Beispiel #1
0
    public override void UpdateCamera(Camera camera)
    {
        if (!Player.Local.IsValid())
        {
            return;
        }

        WorldPos = camera.Pos;
        WorldRot = camera.Rot;

        camera.ViewModelFieldOfView = FieldOfView;

        var newPitch = WorldRot.Pitch();
        var newYaw   = WorldRot.Yaw();

        var pitchDelta = Angles.NormalizeAngle(newPitch - lastPitch);
        var yawDelta   = Angles.NormalizeAngle(lastYaw - newYaw);

        var playerVelocity = Player.Local.Velocity;
        var verticalDelta  = playerVelocity.z * Time.Delta;
        var viewDown       = Rotation.FromPitch(newPitch).Up * -1.0f;

        verticalDelta *= (1.0f - System.MathF.Abs(viewDown.Cross(Vector3.Down).y));
        pitchDelta    -= verticalDelta * 1;

        var offset = CalcSwingOffset(pitchDelta, yawDelta);

        offset += CalcBobbingOffset(playerVelocity);

        WorldPos += WorldRot * offset;

        lastPitch = newPitch;
        lastYaw   = newYaw;
    }
Beispiel #2
0
    public override void PostCameraSetup(ref CameraSetup camSetup)
    {
        base.PostCameraSetup(ref camSetup);

        if (!Local.Pawn.IsValid())
        {
            return;
        }

        if (!activated)
        {
            lastPitch = camSetup.Rotation.Pitch();
            lastYaw   = camSetup.Rotation.Yaw();

            activated = true;
        }

        Position = camSetup.Position;
        Rotation = camSetup.Rotation;

        camSetup.ViewModel.FieldOfView = FieldOfView;

        var newPitch = Rotation.Pitch();
        var newYaw   = Rotation.Yaw();

        var pitchDelta = Angles.NormalizeAngle(newPitch - lastPitch);
        var yawDelta   = Angles.NormalizeAngle(lastYaw - newYaw);

        var playerVelocity = Local.Pawn.Velocity;
        var verticalDelta  = playerVelocity.z * Time.Delta;
        var viewDown       = Rotation.FromPitch(newPitch).Up * -1.0f;

        verticalDelta *= (1.0f - System.MathF.Abs(viewDown.Cross(Vector3.Down).y));
        pitchDelta    -= verticalDelta * 1;

        var offset = CalcSwingOffset(pitchDelta, yawDelta);

        offset += CalcBobbingOffset(playerVelocity);

        Position += Rotation * offset;

        lastPitch = newPitch;
        lastYaw   = newYaw;
    }
Beispiel #3
0
    public override void PostCameraSetup(ref CameraSetup camSetup)
    {
        base.PostCameraSetup(ref camSetup);

        if (!Local.Pawn.IsValid())
        {
            return;
        }

        if (!activated)
        {
            lastPitch = camSetup.Rotation.Pitch();
            lastYaw   = camSetup.Rotation.Yaw();

            YawInertia   = 0;
            PitchInertia = 0;

            activated = true;
        }

        Position = camSetup.Position;
        Rotation = camSetup.Rotation;

        var cameraBoneIndex = GetBoneIndex("camera");

        if (cameraBoneIndex != -1)
        {
            camSetup.Rotation *= (Rotation.Inverse * GetBoneTransform(cameraBoneIndex).Rotation);
        }

        var newPitch = Rotation.Pitch();
        var newYaw   = Rotation.Yaw();

        PitchInertia = Angles.NormalizeAngle(newPitch - lastPitch);
        YawInertia   = Angles.NormalizeAngle(lastYaw - newYaw);

        if (EnableSwingAndBob)
        {
            var playerVelocity = Local.Pawn.Velocity;

            if (Local.Pawn is Player player)
            {
                var controller = player.GetActiveController();
                if (controller != null && controller.HasTag("noclip"))
                {
                    playerVelocity = Vector3.Zero;
                }
            }

            var verticalDelta = playerVelocity.z * Time.Delta;
            var viewDown      = Rotation.FromPitch(newPitch).Up * -1.0f;
            verticalDelta *= (1.0f - System.MathF.Abs(viewDown.Cross(Vector3.Down).y));
            var pitchDelta = PitchInertia - verticalDelta * 1;
            var yawDelta   = YawInertia;

            var offset = CalcSwingOffset(pitchDelta, yawDelta);
            offset += CalcBobbingOffset(playerVelocity);

            Position += Rotation * offset;
        }
        else
        {
            SetAnimParameter("aim_yaw_inertia", YawInertia);
            SetAnimParameter("aim_pitch_inertia", PitchInertia);
        }

        lastPitch = newPitch;
        lastYaw   = newYaw;
    }