Reverse Speed Question

edited November 2013 in Questions about Code

I am a beginner in processing and I am trying to reverse the speed of the balls falling down on collision. How do I go about altering the code? The new line should fit right under println(); and I know there is a collision as print line is telling me there is, nothing is happening after wards. Thanks alot! btw im using kinect and this is just one class. Line is right above the slashes.

  float xp;
  float yp;
  float he;
  float si;
  float y;
  float a = random(0, 255);
  float b = random(0, 120);
  float c = random(0, 255);
  float boxposX = xp;
   float boxposY = yp;

   float randomspeed; 
  circle(float h, float s) {
    yp = y;
    he = h;
    si = s;
  }
  void move() {
    if (yp >= 500) {
      randomiser();
      float randomnumberup = random(-500, 0);
      yp = randomnumberup;
    }
    else {
      float randomspeed = random(1, 6);
      yp = yp + randomspeed;
    }

    // collision
     float d = dist(yp, xp, handX, handY);
     if ( d < handDiam/2 + si/2) {

      println(d); 






      //////////////////////////////////////////


     }
  }
  void display() {
    noStroke();
    fill(a, b, c);
    rect(xp, yp, he, si);
  }
  void randomiser() {
    xp = random(5, 480);
  }
}

Answers

  • edited November 2013

    To reverse a speed, you just change its sign. You can keep the sign in the class, as a variable (+1, -1), and multiply randomspeed with it.

  • I know that. So would my code be

    float randomnumberup = -10000; yp = randomnumberup;

    right above the slashes?

  • edited November 2013

    "I know that"
    I don't see -1, +1 nor multiply in your proposal, so I am not sure what you know or understood. Where this -10000 comes from, why do you put it in a variable just to assign it in the next sentence, how will it change the sign of the speed?

Sign In or Register to comment.