- Home /
Camera Anti-Shake-System
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?
Thanks in advance!
Answer by robertbu · Dec 20, 2013 at 09:43 PM
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.
Thank you for the answer, but unfortunately this did not work for me. For example when the character begins to run, the camera is behind the character because it speeds up to slowly. But if I increase the speed factor there is no smoothing anymore.
Isn't there a way to detect the movement of the headbone to move the camera to the opposide direction of it?
Isn't there a way to detect the movement of the headbone to move the camera to the opposide direction of it?
That's kinda what this script does, though it uses the whole object, not just the head bone. Without your code to play with and perhaps a video reference about what kind of movement you are looking for, all I can do is guess and give alternate solutions of perhaps ever increasing complexity. The next thing I would try is replacing the $$anonymous$$oveTowards() with Lerp() and the RotateTowards() with Slerp(). The rest of the code can remain the same, but the meaning of 'moveSpeed' and 'rotateSpeed' will change, and therefore you will have to reduce their values.
Your answer