Object in front of camera: goes wrong with *10?

Hi,

I would like to put the white rectangle in front of the camera at a certain distance.

It works when the object is at the same location as the camera, just in front of the camera, it copies the right rotation and position. But with a distance between them, such as *10, it does not follow the path of the camera’s forward, and it is located a bit up. Does anyone know why?

Here is an image :

10463-white.png

And the code :

//cam position
cam = Camera.main.transform;
vecCam = cam.position;

//in front of cam
white_Vec = vecCam;
white_Vec -= (cam.position.forward * 10);
rect = Instantiate(Resources.Load("rect1"), white_Vec, Quaternion.identity);

var angles = cam.localEulerAngles;
rect.transform.localEulerAngles = angles;

Thanks a lot

Use TransformPoint. It turns local coordinates, such as 10 units in front of the camera, into world coordinates.

white_Vec = cam.TransformPoint(Vector3.forward*10);
rect = Instantiate(Resources.Load("rect1"),white_Vec, cam.rotation);