Playmaker Forum
PlayMaker Feedback => Action Requests => Topic started by: looi on April 14, 2020, 10: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/ (https://forum.unity.com/threads/how-to-calculate-horizontal-field-of-view.16114/))
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();
}
}
}