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

raycasthit unity

RaycastHit hit;
/*
(Vector3) hit.point - the point where the ray has collided.
(Quaternion) hit.normal - the normal of the GameObject the ray has collided.
(float) hit.distance - the distance between the ray origin and hit.point.
(Transform) hit.transform - the transform of the GameObject the ray has hit
(Rigidbody) hit.rigidbody - rigidbody attached to GameObject ray collided,
							if no rigidbody is attached, value is null.
(Vector2) hit.textureCoord - the coordinate of the point on the texture
							 of the GameObject the ray collided.
*/
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

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 :: color unity 
Csharp :: binary search c# 
Csharp :: turn list of string to csv c# 
Csharp :: connection string in asp.net with username and password 
Csharp :: c# main 
Csharp :: C# function return datareader 
Csharp :: git find commits by file path 
Csharp :: particle system start color 
Csharp :: instantiate unity 2d in parent 
Csharp :: c# concatenation 
Csharp :: roman to int 
Csharp :: string to byte array c# 
Csharp :: dns ttl meaning 
Csharp :: c# sum of array elements# 
Csharp :: 1 line if c# 
Csharp :: unity create empty gameobject in code 
Csharp :: creating a streamwiter file C# 
Csharp :: c# linq distinct group by nested list 
Csharp :: char to digit in java 
Csharp :: c# multiple strings are empty 
Csharp :: c# replace dash in string 
Csharp :: unity create 3d object in script 
Csharp :: c# enum 
Csharp :: c# get the first 4 characters in the list 
Csharp :: is number c# 
Csharp :: c# verify in class exist in list 
Csharp :: how to upload an image to an image source c# 
Csharp :: excel isrlgood 
Csharp :: c# lists 
Csharp :: Data at the root level is invalid. Line 1, position 1. 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =