RAYCASTING
PUBLISHED: 10/06/2023
Last updated
PUBLISHED: 10/06/2023
Last updated
--> a physics function that casts a ray into the scene from the point of origin, in a specified direction, of a length of maxDistance, against all colliders
--> A raycast parameter | Vector3 variable representing the starting point of the ray in world coordinates
--> A raycast parameter | Vector3 variable representing the direction of the raycast
--> A raycast parameter | a float variable representing the max distance the raycast should check for collisions
--> A raycast parameter | A struct that will contain information about the raycast collision within they variable hitInfo
--> A raycast parameter | A struct that specifies which layers to use in a raycast
--> a raycast parameter | an enumeration that specifics whether the raycast should hit triggers or not
--> a raycast parameter | a struct that holds 3 variables to define a raycast (Origin, Direction, maxDistance)
Raycast is a physics function that casts a ray into the scene from the point of origin, in a specified direction, of a length of maxDistance, against all colliders.
Raycasts returns a bool variable on whether or not the ray hit any colliders.
There are 16 different variations of the Raycast declaration, all containing the following parameters...
Origin --> The starting point of the ray in world coordinates | VECTOR3
Direction --> The direction of the ray | VECTOR3
maxDistance --> The max distance the ray should check for collisions | Float
The above line of code creates a raycast that starts at the position of the attached gameobject and casts a ray 10 units forward. If the ray hits another collider, the bool value didHit
is true, else false.
--> If true is returned, hitInfo
will contain more information about where the closest collider was hit | Struct
--> a Layer mask that is used to selectively ignore colliders when casting a ray | Struct
--> Specifies whether this query should hit triggers | Enumeration
--> The starting point and direction of the ray | Struct