- Home /
Let a plane follow the camera
So I have a feeling this is very simple, but can't get it right.
I want a horizon plane to follow the FPS style camera so the plane is always visible on the horizon. I came up with the following script. Problem is Vector forward also calculates directions. So when I look straight ahead, the horizon is at the desired distance. But, when I look up of down with the camera, the horizon comes towards the camera...
horizonObject.transform.position = Camera.main.transform.TransformPoint(Vector3(0, 0, 70));
horizonObject.transform.rotation = Quaternion.LookRotation(horizonObject.transform.position - Camera.main.transform.position);
horizonObject.transform.position.y = 0;
horizonObject.transform.rotation.x = 0;
horizonObject.transform.rotation.z = 0;
Hope someone can help me...
Answer by DoctorMoney · Jul 28, 2014 at 04:47 AM
I'm not sure exactly what you're trying to do, but it sounds like parenting the plane to the camera would work. Just drag and drop it in the inspector and you should be fine. Disable this script when you try it though
Yes, but that will make the plane fly so it's always in view. But I want it to be at the horizon only at y=0;
have you tried this?
public float desiredDistance = 70f; //tweek this on inspector
Vector3 horizonLocation = (camera.transform.position + camera.transform.forward * desiredDistance);
horizonLocation.y = 0; //kills y coordinate so that the plane only moves sideways and back and forth
horizonObject.position = horizonLocation; //Puts the horizon plane on the horizon
horizonObjecto.rotation = Quaternion.LookRotation(horizonObject.transform.position - Camera.main.transform.position); //makes it look at the camera... migth as well use LookAt
etc...
Hope it helps