Hey there,
I have a camera atached to my Rig’s head bone,
as you can imagen the camera moves with every step the player does, I just don’t want to unparent the camera from the headbone because I don’t want to lose completely the camerashake.
And that is my question: has anybody an idea how to make a camera stabilisation script or something like this?
Replace your camera with an empty game object at the same position and rotation. Then use RotateTowards() and MoveTowards() to soften your movements. Untested example:
#pragma strict
public var target : Transform;
public var moveSpeed = 1.0;
public var rotateSpeed = 90.0;
private var myTransform : Transform;
function Start() {
transform.position = target.position;
transform.rotation = target.rotation;
myTransform = transform;
}
function Update() {
myTransform.position = Vector3.MoveTowards(myTransform.position, target.position, moveSpeed * Time.deltaTime);
myTransform.rotation = Quaternion.RotateTowards(myTransform.rotation, target.rotation, rotateSpeed * Time.deltaTime);
}
Attach this script to the camera, then drag and drop the empty game object on the ‘target’ variable in the Inspector. You will need adjust ‘moveSpeed’ and ‘rotateSpeed’ so that the correct amount of shake comes through.