Legacy Documentation: Version 5.4
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

RaycastHit2D.centroid

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

Sumbission failed

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

Close

Cancel

public var centroid: Vector2;
public Vector2 centroid;

Description

The centroid of the primitive used to perform the cast.

When the RaycastHit2D is returned from line or ray casting, the centroid is identical to the return point property however when using cast methods that use a geometry shape (as opposed to a simple point) such as circle or box casting, the centroid is the center of the respective shape when it is in contact with the returned point.

The centroid is useful in determining the position the cast shape should be for it to collider at the contact point. Note that the point takes into account any rotation specified for the shape when it was cast.

See Also: See Also: point, Physics2D.Raycast, Physics2D.Linecast, Physics2D.CircleCast & Physics2D.BoxCast.