Documentation index for AI agents (llms.txt) A Markdown version of every page is available: request the page's source under /docs/, follow the "alternate" link in this page's head, or start from /llms.txt.
Visual Script logo Manual

Direction from Camera#

Input / Direction from Camera

  • Can Read

  • Cannot Write

Description#

Converts a Vector2 input into a world direction relative to a Camera

Parameters#

Name Description
Direction The Vector2 input that is converted into a world direction
Camera The Camera the resulting direction is relative to

Code#

using System;
using UnityEngine;
using VisualScript.Icons;

namespace VisualScript.Runtime
{
    [Get]

    [Title("Direction from Camera")]
    [Category("Input/Direction from Camera")]

    [Description("Converts a Vector2 input into a world direction relative to a Camera")]
    [Image(typeof(IconCamera), ColorTheme.Type.Blue, typeof(BadgeArrowUp))]

    [Parameter("Direction", "The Vector2 input that is converted into a world direction")]
    [Parameter("Camera", "The Camera the resulting direction is relative to")]

    [Keywords("Move", "Relative", "Forward", "Right", "Plane", "Ground")]

    [Serializable]
    public class TypeVector3InputDirectionFromCamera : TypeVector3
    {
        [SerializeField] private GetVector2 m_Direction = new GetVector2();

        [SerializeField]
        private GetGameObject m_Camera = new GetGameObject(new TypeGameObjectCameraMain());

        public override Vector3 Get(Args args)
        {
            Vector2 direction = this.m_Direction.Get(args);

            GameObject camera = this.m_Camera.Get(args);
            if (camera == null) return new Vector3(direction.x, 0f, direction.y);

            Transform transform = camera.transform;

            Vector3 forward = Vector3.ProjectOnPlane(transform.forward, Vector3.up);
            if (forward.sqrMagnitude <= Vector3.kEpsilon)
            {
                forward = Vector3.ProjectOnPlane(transform.up, Vector3.up);
            }

            forward.Normalize();
            Vector3 right = new Vector3(forward.z, 0f, -forward.x);

            return (right * direction.x) + (forward * direction.y);
        }

        public override string ToString()
        {
            return $"{this.m_Direction} from {this.m_Camera}";
        }

        protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
    }
}
Visual Script logoVisual Script © Catsoft Works 2026. All rights reserved.