# Movement to where I touch on the screen

**URL:** <https://discourse.processing.org/t/movement-to-where-i-touch-on-the-screen/33193>\
**Category:** Coding Questions\
**Created:** [October 31, 2021, 3:18pm UTC](https://discourse.processing.org/t/movement-to-where-i-touch-on-the-screen/33193 "2021-10-31T15:18:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tati1202](https://avatars.discourse-cdn.com/v4/letter/t/9e8a1a/32.png) [@tati1202](https://discourse.processing.org/u/tati1202)\
**Post date:** [October 31, 2021, 3:18pm UTC](https://discourse.processing.org/t/movement-to-where-i-touch-on-the-screen/33193/1 "2021-10-31T15:18:20Z")

</div>

> **[GitHub - GonzaCastro24/tecnomultimedia at tp5](https://github.com/GonzaCastro24/tecnomultimedia/tree/tp5)**
>
> tp5

Hey, I’m working in this videogame where you have to shoot the ball pressing in x place in the net/goal. Does anyone knows how to incorporate this with easy coding? Thanks

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [October 31, 2021, 4:26pm UTC](https://discourse.processing.org/t/movement-to-where-i-touch-on-the-screen/33193/2 "2021-10-31T16:26:37Z")

</div>

Hello,

Lots of resources here:  
_[https://processing.org/](https://processing.org/)_

Look for the _Linear Interpolation_ example and the reference for `lerp()`.

`:)`

---

<div class="post-metadata">

**Author:** ![tati1202](https://avatars.discourse-cdn.com/v4/letter/t/9e8a1a/32.png) [@tati1202](https://discourse.processing.org/u/tati1202)\
**Post date:** [October 31, 2021, 4:37pm UTC](https://discourse.processing.org/t/movement-to-where-i-touch-on-the-screen/33193/4 "2021-10-31T16:37:16Z")

</div>

> [@glv](#):
>
> Hello,
> 
> Lots of resources here:  
> _[https://processing.org/](https://processing.org/)_
> 
> Look for the _Linear Interpolation_ example and the reference for `lerp()` .
> 
> `:)`

okay, thanks, i will

---

<div class="post-metadata">

**Author:** ![tati1202](https://avatars.discourse-cdn.com/v4/letter/t/9e8a1a/32.png) [@tati1202](https://discourse.processing.org/u/tati1202)\
**Post date:** [November 1, 2021, 3:50pm UTC](https://discourse.processing.org/t/movement-to-where-i-touch-on-the-screen/33193/5 "2021-11-01T15:50:36Z")

</div>

I added the lerp function,but still has no smoothness to the movement. This the code i applied:

````auto
class Pelota {
  
  float x, y, ang, vel, arcox=020, arcoy=0, ancho=800, alto=281, endX, endY, pct = 0.00, step = 0.0001;
  PImage pelota;
  
  //constructor
 Pelota(){
    x=width/2;
    y=500;  
    ang=0;
    vel=1;
    pelota=loadImage("pelota.png");
  }
    
  //metodos
 void dibujar(){
  
        
        //pelota
        pushMatrix();
        imageMode(CENTER);
        translate(x,y);
        rotate(radians(ang));
     image(pelota,0, 0);
     popMatrix();
  }
  
  void patear(){
   if((mouseX>arcox && mouseX<arcox+ancho && mouseY>arcoy && mouseY<arcoy+alto) && mousePressed && (pct < 1)) {
      mouseClicked();
      ang=lerp(y,endY,0.05);
      endX = mouseX;
      endY = mouseY;
      x = lerp(x,endX,0.05);
      y = lerp(y,endY,0.05);
      
   
    }
  }
  void resetear(){
    if(y<180){
      ang=0;
      x=width/2;
      y=500;
    }
  } 
}```
````
