- Home /
Raycast2D and origin position Offset
Hi,
I am raycasting from a gameObject that constantly looks for a target. I want to Raycast with an offset from the objects transform.position so i avoid hitting my own colliders.
Here is what I want to do:
Vector2 dir = target.transform.position - transform.position;
RaycastHit2D hit = Physics2D.Raycast(transform.position, dir, rayDistance);
I want to raycast from "Desired offset" in the image.
Also, the gameObject's rotation or direction dont matter because it's independent of the raycasting.
Answer by tanoshimi · Dec 31, 2014 at 07:00 PM
RaycastHit2D hit = Physics2D.Raycast(transform.position + dir.normalized * distanceToOffset, dir, rayDistance);
are you sure? distanceToOffset will make the rays origin be separate from the origin gameobject when it moves.
Your answer
Follow this Question
Related Questions
Raycasting not behaving as expected? 2 Answers
NullReferenceException when using raycast 1 Answer
C# Raycast goes straight into the air 2 Answers