did you try coordinates * Time.deltaTime?
If i were you, i specified speed first, so i can change/manipulate it on runtime, where needed, so there is no need to recompile code to tweak it.
after that i would give names for positions, just in case model has been moved or rotated, so they updates in real time also and i don’t have to worry about calculations.
Not sure what your project is all about, but looks like you just want your camera to fly around looking at your model.
First of all, remember, you are working with Space.Self (local axis), not Global
at the moment you are telling it to “teleport” to those positions, you need however tell code to reduce distance between (subtraction) multiplied by delta time.
// hardcoding tansform positions is a BAD IDEA, but it's your code and question was different
var head : Vector3 = Vector3(0, 1.2, 1.55);
var upperTorso : Vector3 = Vector3(0, 1, 1.325)
var lowerTorse : Vector3 = Vector3(0, .51, 1);
var all : Vector3 = Vector3(0, .75, 0);
// now lets set up smooth and speed
var speed : int = 0;
var smooth : float;
function Update () {
smooth = speed * Time.deltaTime;
}
function OnGUI () {
if (GUI.Button (Rect (10,10,90,25), "Head")) {
transform.Translate (transform.position - head.position * smooth);
}
if (GUI.Button (Rect (10,40,90,25), "Upper Torso")) {
transform.Translate ( transform.position - upperTorso.position * smooth);
}
if (GUI.Button (Rect (10,70,90,25), "Lower Torso")) {
transform.Translate (transform.position - lowerTorso.position * smooth);
}
if (GUI.Button (Rect (10,100,90,25), "All")) {
transform.Translate ( transform.position - all.position * smooth);
}
}
i wrote this code here in quick reply, did not test, just wanted to show you how it’s done
basically to move it smoothly:
- tell unity current position in 3D space (vector3) and that is transform.position
- tell it target position, and that is also Vector3, .position. However they are hardcoded by you. So if model moves somewhere or rotates in local space, transforms will also change. Solution would be adding 4 empty game objects as child objects to your model for your camera to Transform.LookAt; Simple as that
Where ever parent moves, child will move too. So you’d just define those game objects like:
var head : Transform;
var upperTorso : Transform;
var lowerTorse : Transform;
var all : Transform;
Then you simple use unity editor to drag and drop empty game objects into scripts transform values and you are done. This way you can always adjust game objects if you want to manipulate camera later for tweaks
3) you move camera every frame multiplied by “last known time” as in - delta time. This way no matter what FPS your PC runs on, it will move all the same. Also now you can manipulate smooth speed on runtime by single variable
Basically you are moving object by subtracting distance variable from current position to target position, multiplied by smooth or speed every frame.
4) check out Mathf in script references. I believe it’s most powerful tool to manipulate any values in Unity
EDIT: sry fixed transform.Translate