I’m experimenting in creating a natural head movement of a human at standstill in first person perspective. I’ve googled around for any data on this topic without much luck, I’m not sure about what search terms might work.
Anyway, I have created a basic working prototype where the cameras position is slow rotated between random points, it seems a bit jerky despite the lerp and other than reducing the lerp speed further and the maximum / minimum rotation I’m unsure how I can make it seem more natural.
I’d appreciate any input on this and here is the code for anyone that wants to get this up and running in unity and play with it (in Unityscript).
Just attach this script to your main camera and you are off.
#pragma strict
var fromRot: Transform;
var targetRotation = Quaternion.Euler (1.0, 0, 1.0);
function Start () {
}
function Update() {
var lerpSpeed = 0.005f;
var fromRot = gameObject.transform; //get cameras current rotation
// transition camera until we reach targetRotation
if (fromRot.rotation != targetRotation)
{
transform.rotation = Quaternion.Lerp(fromRot.rotation, targetRotation, Time.time * lerpSpeed);
}
else{
//generate new random target
targetRotation = Quaternion.Euler (Random.Range(-1.0, 1.0), 0, Random.Range(-1.0, 1.0));
}
}
Thanks in advance!