- Home /
Camera SmoothFollow place mesh not in the center
Hi,
I am using SmoothFollow camera. Right now I modified it so that the person is not in the center but at the center-bottom. I want to make a person appear in the bottom-left. Please, could you tell me how to modify SmoothFollow more.
![// The target we are following
var target : Transform;
// The distance in the x-z plane to the target
var distance = 10.0;
// the height we want the camera to be above the target
var height = 5.0;
// How much we
var heightDamping = 2.0;
var rotationDamping = 3.0;
// Place the script in the Camera-Control group in the component menu
@script AddComponentMenu("Camera-Control/Smooth Follow")
function LateUpdate () {
// Early out if we don't have a target
if (!target)
return;
// Calculate the current rotation angles
var wantedRotationAngle = target.eulerAngles.y;
var wantedHeight = target.position.y + height;
var currentRotationAngle = transform.eulerAngles.y;
var currentHeight = transform.position.y;
var screenPosition = new Vector3(0,10,0);
// Damp the rotation around the y-axis
currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);
// Damp the height
currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime);
// Convert the angle into a rotation
var currentRotation = Quaternion.Euler (0, currentRotationAngle, 0);
// Set the position of the camera on the x-z plane to:
// distance meters behind the target
transform.position = target.position;
transform.position -= currentRotation * Vector3.forward * distance;
// Set the height of the camera
transform.position.y = currentHeight;
// Always look at the target
var cameraTarget= target.position + screenPosition;
transform.LookAt (cameraTarget);
}][1]
Thank you. I attach a picture.
[1]: /storage/temp/24133-camerafollow.png
The easiest solution is to make a child empty game object of the character. Place the child to the right and above the parent (visible character) object. Have the camera follow the child.
Thank you. I feel like there should be some way to do it in the code
Answer by robertbu · Mar 24, 2014 at 01:32 AM
If you really want to do it in code, an offset can be used and added to the target position. Here is a quick rewrite of the standard SmoothFollow.js script with that change. Set the value of 'offset' in the Inspector. Positive value for x and y will move the object to the lower left.
// The target we are following
var target : Transform;
// The distance in the x-z plane to the target
var distance = 10.0;
// the height we want the camera to be above the target
var height = 5.0;
// How much we
var heightDamping = 2.0;
var rotationDamping = 3.0;
var offset : Vector3 = Vector3.zero;
// Place the script in the Camera-Control group in the component menu
@script AddComponentMenu("Camera-Control/Smooth Follow")
function LateUpdate () {
// Early out if we don't have a target
if (!target)
return;
// Calculate the current rotation angles
var wantedRotationAngle = target.eulerAngles.y;
var pos = target.position + Quaternion.AngleAxis(wantedRotationAngle, Vector3.up) * offset;
var wantedHeight = height + pos.y;
var currentRotationAngle = transform.eulerAngles.y;
var currentHeight = transform.position.y;
// Damp the rotation around the y-axis
currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);
// Damp the height
currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime);
// Convert the angle into a rotation
var currentRotation = Quaternion.Euler (0, currentRotationAngle, 0);
// Set the position of the camera on the x-z plane to:
// distance meters behind the target
transform.position = pos;
transform.position -= currentRotation * Vector3.forward * distance;
// Set the height of the camera
transform.position.y = currentHeight;
// Always look at the target
transform.LookAt (pos);
}
Thank you for the answer. When I test this script it works fine when my person moves horizontally. But the camera misses the person sometimes when the movement is vertical (45 degrees). I used Offsets x=15, y=10, z=0
I edited my script and fixed that problem plus fixed some problems for 3D movement.
Thank you! This works much better, but there is still one thing. So now when it goes downwards (at any angle, ex:45 degrees), then it misses the person because for some reason the camera zooms in. So the camera zooms in when the cart goes downwards and this leaves the person out of the frame.
Your answer
![](https://koobas.hobune.stream/wayback/20220613141011im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
A node in a childnode? 1 Answer
wrong localScale on instantiated object unity 0 Answers
Networking When Offline 1 Answer
Noobish Question Pertaining to JS Movement 2 Answers
How to read "mp3" or "other Audio" file from SDcard in runtime 0 Answers