Anyone know of a way to alter the SmoothFollow script so it follows smoothly the up and down motion like it does the left right motion? From what I could figure out the LookAt command wants to use the world up direction as its up direction. How can this be changed? I am trying to make a camera follow a ship in space.
Thanks
What is the problem with the script as it is now? You should probably use the ship’s up direction as the up direction for LookAt like this.
transfrom.LookAt(target.transform.position, target.transform.up);
Think carefully about what exactly you want the camera to do and then try to figure out what that motion means in math. From there you can code it.
Right now when my ship turns left or right the smooth follow behaves properly. It sees the ship turn a bit and then readjusts the camera position to be directly behind the ship. But when my ship turns up or down the camera still follows the ship but it does not readjust its position directly behind the ship. In short, what I would like the camera to do is always re-allign itself behind the ship no matter what the ship does and the camera’s up should always be the same as the ship’s up. I’ve tried to modify the script myself by copying the x behaviors in it and reapplying them to the y and disabling the height references but no luck. Changing line 58 of the script to transform.LookAt (target.transform.position, target.transform.up); made no difference.
Thanks
Try instead doing a simple follow like this:
var target : Transform;
var sharpness = 1.00;
private var localPos = Vector3;
function Start ()
{
localPos = target.transform.InverseTransformPosition(transform.position);
}
function Update ()
{
targetPos = target.transform.TransformPosition(localPos);
transform.position = Vector3.Lerp(transform.position, targetPos, Time.deltaTime * sharpness);
transform.LookAt(target, target.up);
}
To set up: position the camera behind the ship where you want it, set target to the ship’s transform and adjust sharpness depending on what you want.
Got an error message (Assets/follow.js(13)error BCE0019: ‘TransformPosition’ is not a member of ‘UnityEngine.Transform’.). I tried changing TansformPosition to TransformDirection but still no go.
Sorry for not testing that!! fixed script:
var target : Transform;
var sharpness = 1.00;
private var localPos : Vector3;
function Start ()
{
localPos = target.transform.InverseTransformPoint(transform.position);
}
function Update ()
{
targetPos = target.transform.TransformPoint(localPos);
transform.position = Vector3.Lerp(transform.position, targetPos, Time.deltaTime * sharpness);
transform.LookAt(target, target.up);
}
You da man. This is exactly it. It works great.
Thanks