Shake an object from script

Discussion in 'Scripting' started by FootprintGames, Jun 2, 2012.

  1. FootprintGames

    FootprintGames

    Member

    Joined:
    Mar 6, 2012
    Messages:
    230
    There's someone who can help me shaking an object using script?
  2. flaminghairball

    flaminghairball

    Member

    Joined:
    Jun 12, 2008
    Messages:
    793
    Code (csharp):
    1.  
    2. var speed = 1.0f; //how fast it shakes
    3. var amount = 1.0f; //how much it shakes
    4.  
    5. function Update()
    6. {
    7.   transform.position.x = Mathf.Sin(Time.time * speed);
    8. }
    9.  
  3. harko12

    harko12

    Member

    Joined:
    Jul 6, 2012
    Messages:
    3
    Worked great for me, Thanks!