How do I make something go directly to a specific point?

edited May 2016 in How To...

I'm trying to move something to a specific point and the position of the object will be different every time I want to move it. I tried to do something with the slope and vectors, but I couldn't figure it out. Something that doesn't deal with vectors would be extremely helpful.

Tagged:

Answers

  • Answer ✓

    This is probably the easiest way:

    float tx=100, ty=100, px=100, py=100;
    
    void setup() {
      size(400, 400);
    }
    
    void draw() {
      px = lerp(px, tx, .1);
      py = lerp(py, ty, .1);
      background(0);
      ellipse(px, py, 10, 10);
    }
    
    void mousePressed() {
      tx = mouseX;
      ty = mouseY;
    }
    
  • Yeah, or replace .1 with a float var and increase by .1 till 1.0

Sign In or Register to comment.