Here to record the relevant content of the radiographic examination:
X-ray detection The name is the ray to detect whether the collision with the intersection, and the collision with the collision device intersection, will return a true.
There are many uses of rays: for example, to detect jumps, and to jump to the ground by projecting a ray of radiation to the ground.
Shooting game can be determined by the length of the ray to determine whether the target object is hit, etc.
The main tool classes used are:
Physicsraycasthit Ray projection collisionRay Ray
The first of these is:
physics.linecast Linear projection
A ray projection from the start position to the end position, if interacting with the collision body, returns true.
Debug.drawline (Transform.position, Line_floor.position, color.red, 1f); bool grounded = Physics.linecast (transform.position, Line_ Floor.position, 1 << Layermask.nametolayer ( " ground ));
if (grounded) { Debug.logerror (" A collision occurred "); } Else { debug.logerror (" end of collision "); }
The second type:
A light that can collide with all the collider in the scene. can control the direction of projection and the length of projection
Vector3 fwd = transform. Transformdirection (-vector3.up); bool grounded = ten );
if (grounded) { Debug.logerror (" A collision occurred "); } Else { debug.logerror (" end of collision "); }
The third type:
A light that can collide with all the collider in the scene and return details of the collision.
Raycasthit hit; BOOLGrounded = Physics.raycast (transform.position,-vector3.up, outHit ); //controllable projection distance bool grounded = Physics.raycast (Transform.position,-vector3.up, out hit,100.0); if(grounded) {Debug.logerror ("there was a collision."); Debug.logerror ("Distance is:"+hit.distance); Debug.logerror ("the object being collided with is:"+hit.collider.gameObject.name); } Else{debug.logerror ("End of collision"); }
Note that the information for the collider returned here is sequentially, returning the first collision first, and returning the second after the first collision is completed.
Physics.raycastall All light projections
Casts a ray and returns all collisions, that is, projecting the light and returning a raycasthit[] structure.
raycasthit[] hits; Hits= Physics.raycastall (Transform.position,-vector3.up,100.0F); inti =0; while(I <hits. Length) {Debug.logerror ("there was a collision."); Raycasthit Hit=Hits[i]; Debug.logerror ("the object being collided with is:"+hit.collider.gameObject.name); I++; }
Unity3d Ray Detection