Hello, Not a coder, trying to get my head round this. I'm trying to make a following camera have some lag behind the movements of the target it's following along all three axis, but not rotations. Here's what i've tried to cobble together from the standard Smooth Follow: Code (csharp): // The target we are following var target : Transform; // How much we var heightDamping =1; var SlewDamping = 1; var ForAftDamping = 1; function LateUpdate () { // Early out if we don't have a target if (!target) return; // Calculate the current planes wantedSlew = target.position.x ; wantedHeight = target.position.y ; wantedForAft = target.position.z ; currentSlew = transform.position.x ; currentHeight = transform.position.y ; currentForAft = transform.position.z ; // Damp the slew CurrentSlew = Mathf.Lerp (currentSlew, wantedSlew, SlewDamping * Time.deltaTime); // Damp the height CurrentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime); // Damp the ForAft CurrentForAft = Mathf.Lerp (currentForAft, wantedForAft, ForAftDamping * Time.deltaTime ); // Always look at the target transform.LookAt (target); } I'm sure it's dead obvious what's wrong to you guys but I'm flummoxed. Anyone care to educate me?
It helps to tell us what it does that is wrong, so we might have an idea of what part of the code to concentrate on. What is it doing that you don't want it to do?
Oh sorry! The camera is just following the target normally, i.e there's no lag between target movement and camera movement. I'm trying to make the camera's movement lag slightly behind the target (preferably as a variable i can quickly adjust for testing). Thanks for letting me know what was wrong with my question!
Sorry, I'm not the best person to ask right now, I'm suffering from a lack of sleep (too much Unity scripting until the late hours of the morning, to be honest!). Have you tried tweaking the damping amounts? Depending on how fast the target object is moving, you might not notice a Lerp with a "damping" value of 1.0. Try making it 0.1, which is a sloooooow lerp. When I'm lerping positions I tend to store the positions as two Vector3 variables, since they come with their own handy-dandy Vector3.Lerp() function, although you don't get the lerp-amount control over each axis as your method does.
Seems to me there's a couple of things wrong with this. First off, it seems you're declaring 6 variables, 3 of whose names differ only by case (the capitalisation of the first letter): currentSlew, currentHeight, currentForAft CurrentSlew, CurrentHeight, CurrentForAft In Unity (yes even in Unity's JS), variables are case sensitive, so the second set of 3 variables are different and separate from the first 3, so this may cause you some confusion if it wasn't intentional in your script. Secondly, there seems to be nowhere in your code where these values are actually applied to the camera's position - so I don't understand how you are seeing your camera move at all, unless by 'move' you mean rotate! And lastly - and these are aesthetic rather than function problems - if you're going for proper terminology, it's "Fore" not "For". Plus, "Slew" is generally used to describe the rotation around the Z axis, so it's not really appropriate for a variable which represents a positional value. hope this helps! - Ben