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

Mouse Ray Direction#

Input / Mouse Ray Direction

  • Can Read

  • Cannot Write

Description#

Returns the direction of a ray that goes from the Camera through the Mouse

Parameters#

Name Description
Camera The Camera the ray is cast from

Code#

using System;
using UnityEngine;
using UnityEngine.InputSystem;
using VisualScript.Icons;

namespace VisualScript.Runtime
{
    [Get]

    [Title("Mouse Ray Direction")]
    [Category("Input/Mouse Ray Direction")]

    [Description("Returns the direction of a ray that goes from the Camera through the Mouse")]
    [Image(typeof(IconCursor), ColorTheme.Type.Blue,  typeof(BadgeArrowRight))]

    [Parameter("Camera", "The Camera the ray is cast from")]

    [Keywords("Cursor", "Screen", "Ray", "Aim", "Forward", "Look")]

    [Serializable]
    public class TypeVector3InputMouseRayDirection : TypeVector3
    {
        [SerializeField]
        private GetGameObject m_Camera = new GetGameObject(new TypeGameObjectCameraMain());

        public override Vector3 Get(Args args)
        {
            Mouse mouse = Mouse.current;
            if (mouse == null) return default;

            Camera camera = this.m_Camera.Get<Camera>(args);
            if (camera == null) return default;

            return camera.ScreenPointToRay(mouse.position.ReadValue()).direction;
        }

        public override string ToString()
        {
            return "Mouse Ray Direction";
        }

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