- Home /
Physics2D.Raycast(localPos vs pos, Vector2.up) ?
Is there any difference what parameter we're going to use for the position in Raycast? transform.localPosition or transform.position
Answer by HarshadK · Dec 17, 2014 at 05:40 AM
Yes, it does matter when your transform.localPosition is not same as transform.position since your point of origin for Raycast will change with use of either of these.
The transform.localPosition gives the position of your object with respect to its parent whereas the transform.position is the world position of your object. So if your object has no parent game object then your transform.localPosition and transform.position will be the same.
http://prntscr.com/5hqurt - my case
Okay what if I want to check with a raycast if the selected on the screenshot platform is below the player? Both of them have different parents which one am i supposed to use?
transform.localPosition is always with respect to the parent of the object whose localPosition you are accessing.
In your case just use transform.position of your player.
Your answer
Follow this Question
Related Questions
Is it possible to check how much a trigger is filled by %? 1 Answer
c# How do I set up continuous raycast collision detection? 1 Answer
Raycast Mouse Click On Specific Objects Only 0 Answers
Creating 2d image map of objects based off 3d space colliders Unity C# 0 Answers
How to Find Owner of a Trigger? 1 Answer