Skip to content

format

typescript
RaycastHit.normal

class: RaycastHit

description

(Read-only) The normal of the surface hit by the ray.

You can use this method to get the surface normal at the intersection point for rendering, reflection calculations, physics reactions, and other operations on the object's surface.

parameter

param_nametypedescription

reture

typedescription
Vector3The normal vector.

code example

typeScript
class New_TypeScript
    extends Component {

        private boxCollider:BoxCollider;
        private ray:Ray;

    OnStart(): void {
        
        this.boxCollider = this.gameObject.GetComponent<BoxCollider>(BoxCollider);

    }

    OnUpdate(): void {

        // Create a ray from (0,0,0) towards the positive Y axis
		this.ray = new Ray(new Vector3(0,0,0),new Vector3(0,1,0));
        let hit = this.boxCollider.Raycast(this.ray,10000)
        hit.normal;
       
    }
}