Skip to content

Instantly share code, notes, and snippets.

@poemdexter
Created July 5, 2014 04:12
Show Gist options
  • Save poemdexter/333293fe7aa56559de90 to your computer and use it in GitHub Desktop.
Save poemdexter/333293fe7aa56559de90 to your computer and use it in GitHub Desktop.
2D raycast for Unity3D
RaycastHit2D hit = Physics2D.Raycast((Vector2)transform.position, direction, length, layerMask);
// check hit in direction
if (hit.collider != null) {
// we hit something check what it is
if (hit.collider.gameObject.CompareTag("wall")) {
// we hit a wall so don't translate in this direction
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment