Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

raycast unity

RaycastHit hit;
        // Does the ray intersect any objects excluding the player layer
        if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity, layerMask))
        {
            Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow);
            Debug.Log("Hit");
        }
        else
        {
            Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * 1000, Color.white);
            Debug.Log("No Hit");
        }
Comment

raycasting in unity

RaycastHit hit;
        // Does the ray intersect any objects excluding the player layer
        if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity, layerMask))
        {
            Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow);
            Debug.Log("Did Hit");
        }
Comment

raycasting in unity


Ray ray = new Ray(position, direction);
RaycastHit hit2;
if (Physics.Raycast(ray, out hit2, maxStepDistance))
{
    reflDirection = Vector3.Reflect(direction, hit2.normal);
    hitPosition = hit2.point;
}
else
{
    position += reflDirection * maxStepDistance;
}

Debug.DrawRay(hitPosition, reflDirection, Color.green);

Comment

unity reflect raycast

Ray ray = new Ray(position, direction);
RaycastHit hit2;
if (Physics.Raycast(ray, out hit2, maxStepDistance))
{
    reflDirection = Vector3.Reflect(direction, hit2.normal);
    hitPosition = hit2.point;
}
else
{
    position += reflDirection * maxStepDistance;
}

Debug.DrawRay(hitPosition, reflDirection, Color.green);
Comment

raycasting unity

RaycastHit target;

        float raydistance = 50;
        Debug.DrawRay(beamorigin.position, transform.forward*raydistance, Color.yellow);
        if (Physics.Raycast(beamorigin.position, transform.forward*raydistance, out target, raydistance, targetlayer))
        {
            Debug.Log(target.collider.tag);
        }
Comment

PREVIOUS NEXT
Code Example
Csharp :: expando object c# 
Csharp :: unity get max occurrence in list 
Csharp :: c# if isset 
Csharp :: c# substring reverse 
Csharp :: working with registry in c# 
Csharp :: how to sort a dictionary by value in c# 
Csharp :: select distinct two columns entity framework c# 
Csharp :: c# make a automapper 
Csharp :: remove duplicates in the list using linq 
Csharp :: ultimate space cruiser 
Csharp :: audio unity 
Csharp :: c# static 
Csharp :: sieve 
Csharp :: serenity frameword order column 
Csharp :: push c# array 
Csharp :: ArgumentException: Input Key named: Fire1 is unknown 
Csharp :: monegame deltatime 
Csharp :: telerik mvc grid column with icon 
Csharp :: How to create a Blazor server-side application in command prompt 
Csharp :: top down view movement script 
Csharp :: c# object is enum 
Csharp :: c# how to delete all files in directory 
Csharp :: oracle c# parameters wont work 
Csharp :: c# if statement no braces 
Csharp :: c# mock ref parameter 
Csharp :: w3develops 
Csharp :: what is failure 
Csharp :: c# switch expression pattern matching 
Csharp :: c# insert backslash in string 
Csharp :: c# subtract 24 hours form datetime 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =