Version: Unity 6 Preview (6000.0)
LanguageEnglish
  • C#

RaycastHit2D.normal

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public Vector2 normal;

Description

The surface normal of the detected Collider2D.

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.