Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


normal

The surface normal of the detected Collider2D.
Read time 1 minuteLast updated 4 days ago

Definition

  • Type: Property
  • Namespace: UnityEngine
  • Assembly: UnityEngine.Physics2DModule
public Vector2 normal { get; set; }

Remarks

When the physics query detects an intersection of a Collider2D at a specific RaycastHit2D.point the
normal
is the surface normal of the Collider2D at that position. A surface normal is a vector perpendicular to the collider surface edge in a direction pointing away from the collider.
Additional Resources: RaycastHit2D.point.
using UnityEngine;public class ExampleClass : MonoBehaviour{ public Vector2 direction; void Update() { // Cast a ray in the direction specified in the inspector. RaycastHit2D hit = Physics2D.Raycast(transform.position, direction); // If something was hit, draw a line from the hit position in the direction of the surface normal. if (hit) Debug.DrawLine(hit.point, hit.point + hit.normal, Color.yellow); }}
Note: If a hit starts occuring inside a collider, the collision normal is the opposite direction of the line/ray query.