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

for loop increment less than 1 (JS)

Discussion in 'Scripting' started by RevolutionNow, Feb 11, 2015.

  1. RevolutionNow

    RevolutionNow

    Joined:
    Oct 12, 2013
    Posts:
    8
    Hi Does anybody why unity freezes if you have the increment in a for loop beeing less than one?

    I can show you my example

    Code (JavaScript):
    1. for (var t = 0; t < 10;t= t+0.5){
    2.  
    3.    finalTransformY = initialTransformY + yVelocity * t - 0.5 * gravity * t * t;
    4. finalTransformX = initialTransformX + xVelocity * t;
    5. finalTransformZ = initialTransformZ + zVelocity * t;
    Any thoughts? :)
     
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    what happens if you type t as a float?
     
  3. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    It probably thinks t is an int and not a float.
     
  4. RevolutionNow

    RevolutionNow

    Joined:
    Oct 12, 2013
    Posts:
    8
    Then it works :D
     
  5. RevolutionNow

    RevolutionNow

    Joined:
    Oct 12, 2013
    Posts:
    8
    yes that was correct :)