var translationSpeed = 1
function Update() {
transform.LookAt(target);
}
I would like to be able to put a rotation speed to the camera, 1 would follow the target as usual on the LookAt. And 0 a still camera.
Thanks
var translationSpeed = 1
function Update() {
transform.LookAt(target);
}
I would like to be able to put a rotation speed to the camera, 1 would follow the target as usual on the LookAt. And 0 a still camera.
Thanks
Before writing your own lookat() function, wouldn’t the SmoothLookAt() script from the standard assets do what you want? Instead of the speed variable control you want it uses damping, but the same effect should be achievable. The speed in SmoothLookAt is not constant though (fast if it still needs to rotate a lot, slow if it is almost there). So alternatively, you could just look at how it is written for hints on how to make your own script.
Edit:
Ooh, liquidgraph posted a rotation script using Quaternion.Lerp in the following thread: http://forum.unity3d.com/viewtopic.php?t=30722&start=0
I tryed a falling cube and the smooth camera to follow it, it follow but it shake.
I’m not sure if it helps, but I was working on this just before and it uses smooth adjustments of the camera position and rotation. Put this script on the camera, and then give it a target (player character or just a cube, I guess).
If you hold Ctrl or LMB, it will zoom in, adjust the position and rotation of the camera.
It’s not a complete camera system yet (it looks at the target, but is fixed in place), but maybe it will help you understand how to smooth movement?
To anyone else reading, please critique my code - I’m fairly new to programming and would appreciate it!
var target : Transform;
var normFocusOffset = Vector3(0.0, 2.2, 0.0);
var zoomFocusOffset = Vector3(0.0, 2.8, 0.0);
var normCameraOffset = Vector3(0.0, 3.0, -3.0);
var zoomCameraOffset = Vector3(0.0, 2.5, -1.0);
var cameraSmoothing = 5.0;
private var currentFocusOffset;
private var currentCameraOffset;
function LateUpdate() {
if(!Input.GetButton("Fire1")) {
currentFocusOffset = normFocusOffset;
currentCameraOffset = normCameraOffset;
} else {
currentFocusOffset = zoomFocusOffset;
currentCameraOffset = zoomCameraOffset;
}
// smooth transition to new position
transform.position = Vector3.Lerp(transform.position, target.position + currentCameraOffset, Time.deltaTime * cameraSmoothing);
// smooth transition to new rotation
var relativePos = (target.position + currentFocusOffset) - transform.position;
targetRotation = Quaternion.LookRotation(relativePos);
transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, Time.deltaTime * cameraSmoothing);
}
Er, I mean it isn’t fixed in place but doesn’t orbit to stay behind the target.
Just what we needed !!!
Thank You Sir.
Nice and well explained snippet. Really helped! Thank you !