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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

how to change itween shake position speed/ frequency?

Discussion in 'Editor & General Support' started by greencindy, Oct 29, 2012.

  1. greencindy

    greencindy

    Joined:
    May 10, 2012
    Posts:
    17
    Hi there,

    I attached the shake position script to a object, but find that the object shakes quite fast. I want to make it moves like slower swing. How could I change the speed (frequency) of the shake? Thanks so much!

    Lee
     
  2. mastermindsdei

    mastermindsdei

    Joined:
    Dec 29, 2016
    Posts:
    3
  3. Eriks-indesign

    Eriks-indesign

    Joined:
    Aug 15, 2012
    Posts:
    50
  4. djorgri

    djorgri

    Joined:
    Jan 3, 2011
    Posts:
    18
    Just for your interest,
    i made a little script for my own needs, moving some cloud sprites in a random way, using iTween :

    Code (CSharp):
    1. float shakeAmplitude = 0.3f;
    2. float shakeFrequency = 5f;
    3. Vector3 originPosition;
    4.  
    5. void Start()
    6. {
    7.   originPosition = transform.position;
    8.   InvokeRepeating("NewRandomPosition", 0f, shakeFrequency);
    9. }
    10.  
    11. void NewRandomPosition()
    12. {
    13.   Vector3 newPosition = originPosition + (Random.insideUnitSphere * shakeAmplitude);
    14.   iTween.MoveTo(gameObject, iTween.Hash(
    15.     "delay", Random.Range(0, shakeFrequency),
    16.     "position", newPosition,
    17.     "time", shakeFrequency,
    18.     "easetype", iTween.EaseType.easeInOutSine
    19.     ));
    20. }
     
    Last edited: Oct 24, 2017