- Home /
make a target camera?
I wonder if anyone might have a perspective on how to do the following- I have a series of targets to .LookAt given various UI or keyboard inputs. I want to set the camera to rotate the object looked at i.e Target Camera. However, when I move away from the target through WASD or LMB, I want the camera axis to return to the camera.
Any idears? Many Thanks!
I have a hard time understanding what you wrote. Even if English is not your first language try to correct the grammar in your sentences. What does "I want to set the camera to rotate the object looked at i.e Target Camera" mean? Why should the camera rotate another object? Do you mean that the camera should rotate towards the object? Also, what does "I want the camera axis to return to the camera." mean?
He wants a camera that focuses onto objects, and when the objects are far away the camera will return to it's initial rotation.
http://answers.unity3d.com/questions/948832/foreach-loop-only-going-through-once-c.html
This guy had a similar problem, the camera doesn't return to it's original rotation when far away. But it should be enough to give OP an idea how to start and accomplish the problem. Also check out the StandardAssets, there's a follow camera script that should bring some insight.
I apologize, I left out the word "around" as in "I want to set the camera to rotate around the object looked at, i.e a Target Camera" that is to say, I want to make the axis of the camera be the axis of the object it is looking at - the target- essentially making it a target camera, a camera which is looking toward the target as it rotates around it at a specific distance.
However when it (the camera ) is moved whether by WASD keys or by a mouse button press( I have the left mouse button set to move the camera forward, the right to rotate it) I want to make it more like a free camera, one that has it's axis centered in the camera, so that when it rotates it is simply turning in place.
$$anonymous$$akes sense?
Thanks for the link, Jessespike ,but not quite what I am looking for as I am not so much trying to focus on an object as make it the point around which the camera orbits, while always looking at it.
Thanks again for help offered.
Answer by InfernoZYB · Apr 24, 2015 at 04:41 PM
This one was a little different but i have made a script for you! :D Hope it works to what you need it for and if you need help comment below.
using UnityEngine;
using System.Collections;
public class LootAtTargetCamera : MonoBehaviour {
Quaternion DefaultRotation;
Vector3 Distance;
public float maxdistance = 20;
public GameObject camera;
public GameObject target;
// Use this for initialization
void Start () {
DefaultRotation = camera.transform.rotation;
}
// Update is called once per frame
void Update () {
//Debug.Log (Vector3.Distance (camera.transform.position, target.transform.position));
if (Vector3.Distance (camera.transform.position, target.transform.position) <= maxdistance) {
camera.transform.LookAt (target.transform);
} else {
camera.transform.rotation = DefaultRotation;
}
}
}
Just put this script on and assign the camera and the target and the distance then it should work. Here is a preview of it(The "camera" is in the top corner but you can change that on yours):