- Home /
Follow an object with camera
Hi,
Now I'm throwing an object from my Main Camera.I need to follow that object with the same camera or another camera.Help me with some eg.
Thanks
Manoj
Answer by Claytonious · May 18, 2012 at 08:57 AM
Attach something like this script to your thrown object. This would keep your camera 5 units behind and 5 units above the thrown object. If you want something more specific then please ask more specifically.
public Vector3 cameraFollowOffset = new Vector3(0,5,-5);
public Camera followCamera;
void Start()
{
if (followCamera == null)
followCamera = Camera.mainCamera;
}
void Update()
{
followCamera.transform.position = transform.position + cameraFollowOffset;
}
Hi $$anonymous$$r.Clay Fowler, It works great!! Thanks.
Can you please tell how reset camera to old view.
Thanks
have a transform storage variable, and before you do the following copy the current transform to the storage, and when your done paste the storage to the actual transform
im trying to something similar to this, but to a ball that will be jumping. I copy paste this in there and i get errors. So here they are and maybe you can help.
Assets/Ball_Control.js(25,14): BCE0043: Unexpected token: Vector3.
Assets/Ball_Control.js(26,12): BCE0043: Unexpected token: Camera.
@$$anonymous$$aguire - you apparently pasted this C# code fragment into a Javascript file. The above is a fragment from a complete C# class.