I have car model which is build from different parts (separate 3d meshes such as mirrors, bumpers, wheels etc) all contained in Unity GameObject’s hierarchy. The car itself stands on a cylindrical platform. Based on a part of user choice I would like it to have positioned/rotated towards the camera. For example if a mirror has been selected I would like the platform to rotate so that the mirror would become aligned with camera view. I’m attaching the code I’ve been working on, which of course has some errors. Help highly appreciated.
public class PlatformBase : MonoBehaviour {
private Transform selection; // selected part
private Quaternion q;
void Update ()
{
transform.rotation = Quaternion.Lerp(transform.rotation, q, Time.deltaTime);
}
public Transform Selection
{
set
{
selection = value;
angle = Vector3.Angle(
-Camera.main.transform.forward,
new Vector3(selection.forward.x, 0.0f, selection.forward.z).normalized);
q = Quaternion.AngleAxis(angle, Vector3.up);
}