I have a camera, which can rotate and move in the world freely, in every direction. I have a 3D object, and when I push a button, I want that object to “fly” (animate) in front of my camera, in good orientation, no matter in what position my camera is. See the picture: I want this instrument to animate to the camera, and I want to see it always in that position relative to the camera. (Of course, once it is in the good position I can parent it to the camera.) I also want to scale the model, that it can fit in the viewport of the camera. How can I do this?
I edited my code as Berenger suggested, but I am doing something wrong, please someone review my code, maybe you can spot the mistakes.
Thx for the help, I am trying to accomplish, waht you described, but it’s not seems to work yet. Please look at my code, maybe you can spot the mistakes. I was also using this pic:
//half of the collider height
height=gameObject.collider.bounds.size.y/2;
//camera horizontal field of view
h_fov= Camera.main.fieldOfView;
//screen ratio
rat= (float)Screen.height/ (float)Screen.width;
//according to the linked picture: tan(vertical FOV/2)
tan_v_fov_per_two=rat*Mathf.Tan((h_fov/2)*(Mathf.PI/180));
//distance from camera
distance = height / tan_v_fov_per_two;
//animate in front of the camera (my cam position: x=0,y=200, z=0)
iTween.MoveTo(gameObject, new Vector3(Camera.main.transform.position.x,Camera.main.transform.position.y-distance, Camera.main.transform.position.z),2);