- Home /
Diagonal Raycast - Origin problem
Hey, I've got a small problem when trying to raycast a diagonal line from a moving and rotating object. The problem is that the origin point is not the objects exact position, it is a point slightly to the right of the objects transform.
This would be simple however the objects position is given in world coordinates which means that changing the rays x origin to transform.position.x+3 will not always move the ray to the right of the object, but on the x axis of the world..
Here's the code:
var diagonal = transform.TransformDirection(1, 0, 1);
Debug.DrawRay(Vector3(transform.position.x-3, transform.position.y, transform.position.z), left*34, Color.blue);
I'm sure there is a simple way of getting the rotating objects local position and moving the ray accordingly. I have tried localPosition however since the object has no parent it still returns world coordinates.
Thanks
Answer by spinaljack · Dec 24, 2012 at 03:11 PM
Try:
position = transform.position-transform.right*3;
Your answer
Follow this Question
Related Questions
Converting Raycasted Point to Local Space 2 Answers
How to get Vector3.down in world space? 1 Answer
Gui point to world position 1 Answer
world and local locations.. 1 Answer