- Home /
Ray rotation with edge of character rather than centre.
I have a shape that I can rotate and move forwards/backwards. I can draw a ray from the centre of the shape which works fine as I move the shape but if I want to draw the ray from the one edge of the shape I get problems when I rotate. Here's the ray coming out of the object on the extreme edge:
Here's if I rotate 90 degrees:
These lines draw the ray:
float left = shapeCentre.x - (shapeSize.x/2);
float x = shapePos.x - left;
ray = new Ray(new Vector3(x,shapePos.y,shapePos.z), transform.forward);
Debug.DrawRay(ray.origin,ray.direction);
When I rotate object the ray rotates but maintains it's origin not reflecting the changing position of the outer edge of the shape as it rotates.
I only move in the X and Z directions and I can see that I need to recalculate the x and z vectors to include the rotation and direction to establish where the edge of the shape moves as it rotates. The problem is that I can't work out how to do it, can anyone help, or is there an easier way to do this.
Thanks sd
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
How to set an exact Local angle. 0 Answers
Spinning a sphere, like a globe. 1 Answer
Having an issue with child rotation working correctly, any help? 1 Answer
Movement rotation 1 Answer