Search Unity

FPS bobbing head

Discussion in 'Scripting' started by Twidusk Studios, Aug 17, 2010.

  1. Twidusk Studios

    Twidusk Studios

    Joined:
    Aug 13, 2010
    Posts:
    42
    Hello to the forums!

    How am i to make my FPS controller bob up and down when i move around? using animations works fine but its a bit annoying and is very buggy. is there anyway that i can use vectors or something?
     
  2. Jesse Anders

    Jesse Anders

    Joined:
    Apr 5, 2008
    Posts:
    2,857
    Sure. Assuming the camera is a separate child object (which it is in the prefab that comes with Unity), you could attach a script to the 'camera' child object that moves it up and down along the y axis using, say, a sine function. You can then activate the effect when the player is moving and deactivate it when the player is not moving to get a basic 'bobbing' effect.

    In practice, you'll probably want to tweak the effect a bit. For example, you don't want the bobbing to just stop abruptly when the player stops moving, as that would seem unnatural. Instead, you can let the 'bobbing' complete its current cycle so that it smoothly comes to rest at (local) y = 0.

    A more involved bobbing effect might also involve rolling from side to side a bit, but I'd recommend getting the basic 'vertical' bobbing effect working first before worrying about that.
     
  3. Twidusk Studios

    Twidusk Studios

    Joined:
    Aug 13, 2010
    Posts:
    42
    Thanks! Ill check it out.