# Idle camera bob script?

**URL:** <https://discussions.unity.com/t/idle-camera-bob-script/66777>\
**Category:** Questions & Answers\
**Created:** [March 24, 2013, 6:07pm UTC](https://discussions.unity.com/t/idle-camera-bob-script/66777 "2013-03-24T18:07:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kranjo](https://avatars.discourse-cdn.com/v4/letter/k/b5e925/32.png) [@kranjo](https://discussions.unity.com/u/kranjo)\
**Post date:** [March 24, 2013, 6:07pm UTC](https://discussions.unity.com/t/idle-camera-bob-script/66777/1 "2013-03-24T18:07:05Z")

</div>

I want to know how to make my camera bob not only when my character moves, but also when it is idle. So, when I move, it executes the camera bob script I already have scripted, and when I am not moving, it rotates the camera just a bit.

The camera bobbing script I already have is this:

```
private var timer = 0.0; 
var bobbingSpeed = 0.18; 
var bobbingAmount = 0.2; 
var midpoint = 2.0; 

function Update () { 
   waveslice = 0.0; 
   horizontal = Input.GetAxis("Horizontal"); 
   vertical = Input.GetAxis("Vertical"); 
   if (Mathf.Abs(horizontal) == 0 && Mathf.Abs(vertical) == 0) { 
      timer = 0.0; 
   } 
   else { 
      waveslice = Mathf.Sin(timer); 
      timer = timer + bobbingSpeed; 
      if (timer > Mathf.PI * 2) { 
         timer = timer - (Mathf.PI * 2); 
      } 
   } 
   if (waveslice != 0) { 
      translateChange = waveslice * bobbingAmount; 
      totalAxes = Mathf.Abs(horizontal) + Mathf.Abs(vertical); 
      totalAxes = Mathf.Clamp (totalAxes, 0.0, 1.0); 
      translateChange = totalAxes * translateChange; 
      transform.localPosition.y = midpoint + translateChange; 
   } 
   else { 
      transform.localPosition.y = midpoint; 
   }
}

```

---

<div class="post-metadata">

**Author:** ![Lemoln](https://avatars.discourse-cdn.com/v4/letter/l/b3f665/32.png) [@Lemoln](https://discussions.unity.com/u/Lemoln)\
**Post date:** [December 5, 2013, 10:35am UTC](https://discussions.unity.com/t/idle-camera-bob-script/66777/2 "2013-12-05T10:35:43Z")

</div>

Search for a shake script, not a bobbing one.
