Alright, well I went though the scripting tutorial a lot of things I didn't get, but I'm sure it will come in time. So I started to write a camera smooth script like the one in the tutorial but I wanted mine to be for the Y and X, also using the mouse as an input instead of keyboard. Any way from some reason the it smooths/follows the Y fine but when I add the X part it gets all messed up. I have been messing around with this for hours and thought I needed some help! :? Code (csharp): //target var target : Transform; //distance from target var distance = 10.0; //camera height var height = 5.0; //damping var rotationDampingY = 3.0; var rotationDampingX = 3.0; //how much above the taget we look var lookHeight = 10.0; function LateUpdate () { if (!target) return; wantedRotationAngleY = target.eulerAngles.y; wantedRotationAngleX = target.eulerAngles.x; currentRotationAngleY = transform.eulerAngles.y; currentRotationAngleX = transform.eulerAngles.x; //damping currentRotationAngleY = Mathf.LerpAngle (currentRotationAngleY, wantedRotationAngleY, rotationDampingY * Time.deltaTime); currentRotationAngleX = Mathf.LerpAngle (currentRotationAngleX, wantedRotationAngleX, rotationDampingX * Time.deltaTime); //degrees to radians currentRotationY = Quaternion.EulerAngles (0, currentRotationAngleY * Mathf.Deg2Rad, 0); currentRotationX = Quaternion.EulerAngles (currentRotationAngleX * Mathf.Deg2Rad, 0, 0); //position transform.position = target.position - currentRotationY * Vector3.forward * distance + currentRotationX * Vector3.up * height; //look at target transform.LookAt (target.position + Vector3.up*lookHeight); } Thanks sync
What kind of camera style are you going for? I'd suggest "smoothing" by using Vector3.Lerp() for the position and Quaternion.Slerp() for the rotation. -Jon
It's for a 3rd person game, your in space so I want to be able to look in all directions. I'll give that a try, right after I visit the scripting refrence to figure out how to use them :wink: Ill see what I come up with bbl later with my results. Thanks sync
Alright I am defiantly more confused. 1. So .Lerp and .Slerp just find the average 2 numbers higher or lower based on T? 2. I dont get the difference between them 3. A example would be extremely helpful 4. OTEE needs another scripting tutorial some thing to compare to would be nice. thanks sync[/code]
Lerp is linear interpolation. This function can be used between two numbers, two vectors/positions, even between two colors. Slerp is spherical interpolation (hence the S.) It only applies to rotations. It moves the "average" as you call it along the shortest path on the outside of a sphere. Think of it as being a "nicer but slower" interpolation that only applies to rotations. In general you should use it, not Lerp, for rotations. Note also that Lerp/Slerp clamp T to the range [0, 1]. This is very handy when T is a function of time. In effect it means that Lerp won't accidentally move you past the final position/rotation. Hope this helps, Matt
More and more people actually prefer lerping rotations rather than slerping them - in theory, slerping is more correct, as lerping has a tendency to speed up in the middle. This speedup makes it feel more solid as you get an acceleration/decelleration for free. Any errors Lepr would give you usually are lost because you do the rotation adjustments over many frames. They're fairly easy to switch, so try both and if you can't tell the difference, just use Lerp.