Get Point - OuterRimStudios/Utilities GitHub Wiki

TargetUtilities.GetPoint

public static Vector3 GetPoint(Vector3 origin, Vector3 direction, float distance, LayerMask mask)

Parameters

origin Starting position of the ray.

direction Direction the ray will be pointing.

distance Distance the ray will span.

mask Layers with which the ray can collide.

Returns

Vector3 closest point along the ray that hits a detectable layer.

Description

Calculates a point along a ray, hitting specified layers.

using UnityEngine;
using OuterRimStudios.Utilities;

public class ExampleClass : MonoBehaviour
{
    public LayerMask collisionLayers;    //Assuming this is filled in the inspector

    void Start()
    {
        //Returns the point of impact on an object on a specified layer within 50 units in front of this object, otherwise returns the point in front of this object 50 units away.
        Vector3 targetPos = TargetUtilities.GetPoint(transform.position, transform.forward, 50, collisionLayers);
    }
}

public static Vector3 GetPoint(Vector3 origin, Vector3 direction, float distance)

Parameters

origin Starting position of the ray.

direction Direction the ray will be pointing.

distance Distance the ray will span.

Returns

Vector3 Returns a point along the ray at the given distance.

Description

Calculates a point along a ray at the specific distance.

using UnityEngine;
using OuterRimStudios.Utilities;

public class ExampleClass : MonoBehaviour
{
    void Start()
    {
        //Returns the point in front of this object 50 units away.
        Vector3 targetPos = TargetUtilities.GetPoint(transform.position, transform.forward, 50);
    }
}