playMaker

Author Topic: Get Camera Horizontal FOV  (Read 228 times)

looi

  • Playmaker Newbie
  • *
  • Posts: 21
    • View Profile
Get Camera Horizontal FOV
« on: April 14, 2020, 07:05:10 PM »
Hello!

I've done a little action to get the "horizontal FOV" (the horizontal angle of the camera FOV pyramid).
Maybe it's not that useful, but anyway.

(I have copied the code from https://forum.unity.com/threads/how-to-calculate-horizontal-field-of-view.16114/)

Code: [Select]
using UnityEngine;
using System;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Camera)]
[Tooltip("Gets the Horizontal FOV of a Camera.")]
public class CameraGetHorizontalFOV : FsmStateAction
{
[RequiredField]
public FsmGameObject GOCamara;
[UIHint(UIHint.Variable)]
public FsmFloat horizontalFOV;

public override void Reset()
{
GOCamara = null;
horizontalFOV = null;
}

public override void OnEnter()
{
           
            var radAngle = GOCamara.Value.GetComponent<Camera>().fieldOfView * Mathf.Deg2Rad;
            var radHFOV = 2 * Math.Atan(Mathf.Tan(radAngle / 2) * GOCamara.Value.GetComponent<Camera>().aspect);
            horizontalFOV.Value = Mathf.Rad2Deg * (float)radHFOV;

            Finish();
}
}
}