Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Detailed camera bob help

Discussion in 'Scripting' started by PhysicalBeef, Jun 15, 2014.

  1. PhysicalBeef

    PhysicalBeef

    Joined:
    Jun 13, 2013
    Posts:
    150
    Is there anyone that can make or have a script lying around that can make this camera effect?


    If you could give me one, i'd be very grateful. Thank you for further reply.
     
  2. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    No clue what part you refer to at all.
     
  3. smitchell

    smitchell

    Joined:
    Mar 12, 2012
    Posts:
    702
    Code (JavaScript):
    1. private var timer = 0.0;
    2. var bobbingSpeed = 0.18;
    3. var bobbingAmount = 0.2;
    4. var midpoint = 2.0;
    5. function Update () {
    6.     waveslice = 0.0;
    7.     horizontal = Input.GetAxis("Horizontal");
    8.     vertical = Input.GetAxis("Vertical");
    9.     if (Mathf.Abs(horizontal) == 0 && Mathf.Abs(vertical) == 0) {
    10.        timer = 0.0;
    11.     }
    12.     else {
    13.        waveslice = Mathf.Sin(timer);
    14.        timer = timer + bobbingSpeed;
    15.        if (timer > Mathf.PI * 2) {
    16.           timer = timer - (Mathf.PI * 2);
    17.        }
    18.     }
    19.     if (waveslice != 0) {
    20.        translateChange = waveslice * bobbingAmount;
    21.        totalAxes = Mathf.Abs(horizontal) + Mathf.Abs(vertical);
    22.        totalAxes = Mathf.Clamp (totalAxes, 0.0, 1.0);
    23.        translateChange = totalAxes * translateChange;
    24.        transform.localPosition.y = midpoint + translateChange;
    25.     }
    26.     else {
    27.        transform.localPosition.y = midpoint;
    28.     }
    29. }
    From the unity Wiki:

    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;
    }
    }
     
  4. PhysicalBeef

    PhysicalBeef

    Joined:
    Jun 13, 2013
    Posts:
    150

    "Detailed camera bob" like in the first "walkable" part in Call of Duty®: Ghosts

    not like in the worst camera bob on the internet..
     
  5. PhysicalBeef

    PhysicalBeef

    Joined:
    Jun 13, 2013
    Posts:
    150
    it's supposed to start automatically?

    if not, it's at 3:24
     
  6. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Didn't start here :( played from the beginning.
     
  7. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Right well. This is expressive movement. I would simply make several public AnimationCurve values and edit them. Then depending on terrain and effort, blend them in. This is a lot more expressive and almost no real code needed. Sin and Cos isn't going to cut it.