示例#1
0
    // 1. Move weapon position to aiming point.
    // 2. Change camera FOV to show bigger objects in the view.
    private void AnimateAiming()
    {
        float progress = (float)aimingProgress / weaponData.maxAimingProgress;

        if (progress > 0)
        {
            // FOV Adjust
            motor.ApplyCamFov(Mathf.Lerp(1.0f, weaponData.maxFovMultiplier, progress) * defaultFov);

            // WPN 'crosshair' move to cursor
            // Explain:
            // 1. motor.weaponDefaultPosition: The position where [gun body] is.
            // 2. weaponData.weaponAimingPoint: The position where [gun's crosshair] is. Attached to weapon prefab.
            // @Warning: Loosy design !
            // OLD:
            //Vector3 aimTween = motor.globalAimPoint.position - (motor.globalDefaultPoint.position + cam.transform.rotation * weaponData.bodyToAimRelative + bobbingRelativePosition);
            //motor.ApplyWeaponPosition(Vector3.Lerp(Vector3.zero, aimTween, progress));

            // NEW:
            Vector3 aimTween = motor.globalAimPoint.localPosition - weaponData.weaponAimPoint.localPosition - bobbingRelativePosition;
            motor.ApplyWeaponLocalPosition(Vector3.Lerp(Vector3.zero, aimTween, progress));
            // Disable crosshair
            crossHair.SetVisible(false);
        }
        else
        {
            crossHair.SetVisible(true);
        }
    }