- Home /
Test if rotation of two go matches
Hey,
I spawn green boxes you see in the picture. And I can move and rotate the blue cube. Now I want to match the rotation of the two game objects by moving and rotating the blue cube in the "game". My first attempt is to compare the two normal vectors (green box / blue box) in the OnCollision method with the dot product. To do get the normal vector of the blue cube I use a raycast:
Ray ray = new Ray(
Camera.main.transform.position, Camera.main.transform.InverseTransformPoint(
transform.position));
RaycastHit hit = new RaycastHit();
if(transform.collider.Raycast(ray, out hit, Mathf.Infinity)) {
Debug.Log("Hit");
}
But the ray do not hit the blue cube as you can see here:
Blue cube has a mesh collider attatched. Can someone explain why the ray do not hit the cube? Is there maybe a better solution to compare the two rotations?
regards Toa
ray.png
(55.3 kB)
Comment
Answer by whydoidoit · Nov 23, 2012 at 10:07 PM
Well I think what you need to do is this:
var ray = new Ray(Camera.main.transform.position, /*direction to this object*/ transform.position - Camera.main.transform.position);
Your answer
![](https://koobas.hobune.stream/wayback/20220613084416im_/https://answers.unity.com/themes/thub/images/avi.jpg)