Hello! I am new to Unity 3D and I need to know how I can make the camera wobble when u walk in game…like in 1st person…
Thanks!!!
Hello! I am new to Unity 3D and I need to know how I can make the camera wobble when u walk in game…like in 1st person…
Thanks!!!
Here’s a bit of code that will make something wobble based on distance. Note it is designed to be use on a child object. That is (assuming it will work), the controller code would go on an empty game object and this on a child (empty or character mesh).
public class Wobble : MonoBehaviour {
public float amount = 10.0f;
public float speed = 1.0f;
private Vector3 lastPos;
private float dist = 0.0f;
private Vector3 rotation = Vector3.zero;
void Start () {
lastPos = transform.position;
}
void Update () {
dist += (transform.position - lastPos).magnitude;
lastPos = transform.position;
rotation.z = Mathf.Sin (dist * speed) * amount;
transform.localEulerAngles = rotation;
}
}