# [HELP]Object Look At Raycast position

Hi guys,
I’m here another time with another problem that i can’t solve
Ok here is the code

``````var hit : RaycastHit;
var direction = CameraTarget.transform.TransformDirection(Vector3.forward);

if(CameraTarget){
var rotationY = Quaternion.EulerRotation(Vector3(0,Physics.Raycast(CameraTarget.transform.position, direction, hit),0));
var rotationX = Quaternion.EulerRotation(Vector3(Physics.Raycast(CameraTarget.transform.position, direction, hit),0,0));

Misc_a.transform.localRotation = rotationY;
Misc_b.transform.localRotation = rotationX;
}
``````

Ok now i’ll explain.
I have a 3D model of a minigun Platform(like the one on the blackhawk helicopter), now the model if made with 4 parts:

1. The base of the minigun
2. The Misc_a object
3. The Misc_b object
4. The Misc_c object
The base doesn’t move or rotate, the Misc_a must rotate along its own Y axis looking at the Raycast Point (that has the origin from an object above the Main Camera that cast a ray), the misc_b must rotate along its own X axis looking at the Raycast Point, but in my script there are 2 errors related at the Vector3 in the Quaternion.EulerRotation.
Can anyone tell me how to do what i’ve writed above?

Thanks
Bye

Physics.Raycast returns a boolean, not a number. If you want the point the ray hits, it’s hit.point.

For the rotation, you can calculate the vector gun → point, set the y = 0 for Misc_a and x = 0 for Misc_b and affect it to the respective transform.forward.

Maybe:

``````var hit : RaycastHit;
var direction = CameraTarget.transform.TransformDirection(Vector3.forward);

if(Physics.Raycast(CameraTarget.transform.position, direction, hit){

Misc_a.rotation = Quaternion.LookRotation(hit.point);
Misc_a.eulerAngles = Vector3(0, Misc_a.eulerAngles.y, 0); // reset the rotation in x and z axis

Misc_b.rotation = Quaternion.LookRotation(hit.point);
Misc_b.eulerAngles = Vector3(Misc_b.eulerAngles.x, 0, 0); // reset the rotation in y and z axis
}
``````

Firstly, you need to launch the raycast to store the position where it collided with something. Then, you’ll be able to play with this collision point as you want.