- Home /
Camera Target Switch By Tag HELP!
I am trying to make my smooth follow script which is on my camera, to change targets but I am having a hard time scripting this. here is my code
var camera : Camera;
var object : Transform;
function Start () {
object = transform.FindWithTag ("Player").transform;
Camera.LookAt(object);
}
Answer by Paprik · Jul 13, 2014 at 09:05 AM
Depends on how you want to handle the transition.
If you want the camera to smoothly translate to the next target, you'll need to do some math and find the point X distance behind the new target and smoothly (with a certain speed and acceleration) move towards it every update.
If you want the transition to be instantaneous, what I did was have a separate camera following each target and then just switch between those
Example:
public Camera Current;
void Switch(Camera cam) {
Current.enabled = false;
Current = cam;
Current.enabled = true;
}
And to get a camera of an object you got by a tag, you can call its GetComponentInChildren< Camera >() function.
Thank you, I did not know how to use tags with cameras because they are different then tagging an object. By using the GetComponent it should work very well and will be much less complex then finding the point X distance.