- Home /
A little help with this camera script please?
I have downloaded from internet this camera script for smooth follow
using UnityEngine;
using System.Collections;
public class FollowCamera : MonoBehaviour {
public GameObject target;
public float damping = 1;
Vector3 offset;
void Start() {
offset = target.transform.position - transform.position;
}
void LateUpdate() {
float currentAngle = transform.eulerAngles.y;
float desiredAngle = target.transform.eulerAngles.y;
float angle = Mathf.LerpAngle(currentAngle, desiredAngle, Time.deltaTime * damping);
Quaternion rotation = Quaternion.Euler(0, angle, 0);
transform.position = target.transform.position - (rotation * offset);
transform.LookAt(target.transform);
}
}
The problem is that it sets the camera to a position related to the player like this in the image
I wanted the camera to have a rotation like this, being more "horizontally"
I have no idea how to change that, can someone help me?? (The camera is in the scene in position B, but when I start the game, it goes to the position A) image : http://imageshack.us/photo/my-images/202/39794077.png/
Answer by Lovrenc · Jan 02, 2013 at 07:13 PM
What you can do is add a simple object (that you wont render) as a child to your player (or cube in this case) and add that child to this camera script as a target.
You have to offset the new target from the cube - move it above the cube.
Answer by Julien-Lynge · Jan 02, 2013 at 07:08 PM
In the Start() method, the script creates an 'offset' parameter based on where the camera is placed relative to the target. You need to adjust the start position of the camera to be where you want it relative to the target. When the script starts, it will 'lock' to that offset.
This isnt the problem. He has the camera where he wants, he wants it to look above the character not directly into it if i understood correctly.
S/he only mentioned wanting a different rotation (which to me implies a different offset), but yeah, from the screenshot I can see what you mean.
Actually a different rotation and position
The camera is in the scene in position B, but when I start the game, it goes to the position A) image : http://imageshack.us/photo/my-images/202/39794077.png/
I see nothing in this script that would move your camera relative to the target. In this sense answer above seems absolutely correct. It does however fix where camera is looking directly on the target. For that i sugges a child as stated below.
Answer by Landern · Jan 02, 2013 at 07:09 PM
You need to change the offset which is going to be the distance from the target. Modify desiredAngle initialization to change the viewing angle.