# Holding the same angle

**URL:** <https://discourse.processing.org/t/holding-the-same-angle/23919>\
**Category:** Coding Questions\
**Created:** [September 17, 2020, 2:46pm UTC](https://discourse.processing.org/t/holding-the-same-angle/23919 "2020-09-17T14:46:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![koenterheegde57](https://avatars.discourse-cdn.com/v4/letter/k/f05b48/32.png) [@koenterheegde57](https://discourse.processing.org/u/koenterheegde57)\
**Post date:** [September 17, 2020, 2:46pm UTC](https://discourse.processing.org/t/holding-the-same-angle/23919/1 "2020-09-17T14:46:32Z")

</div>

Hi guys,  
A few days ago i posted a question about a bubbleshooter game i wanted to make. I’ve now managed to make the bullet move towards my mouse position, but the angle keeps changing if i move the mouse. I want the angle to be fixed after I press the mouse button.

Hopefully you could help me!

\<Ball b;  
ArrayListbullets;  
void setup(){  
size(840,840);  
b = new Ball();  
bullets = new ArrayList();  
bullets.add(new Bullet());  
}

void draw(){  
background(0);  
b.display();

//Bullets  
Bullet bullet = bullets.get(0);  
bullet.display();  
bullet.move();

}

class Ball{  
float x= width/2;  
float y=height;  
Ball(){  
}

void display(){  
fill(255);  
ellipse(x,y,50,50);  
}

class Bullet{  
float x =width/2;  
float y=height;  
boolean doOnce =false;  
Bullet(){

}

void display(){  
fill(255);  
ellipse(x,y,12.5,12.5);  
}  
void move(){  
float distancex = (mouseX-b.x);  
float distancey = abs(mouseY-height);  
float angle = atan((distancey/distancex));  
if (mousePressed == true){  
doOnce = true;  
}  
if (doOnce == true){  
if (angle\>0){  
x+= 3_cos(angle);  
y-= 3_sin(angle);  
}  
if (angle\<0){  
x-=3_cos(angle);  
y-=3_-sin(angle);  
}}}  
}

>

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [September 17, 2020, 4:00pm UTC](https://discourse.processing.org/t/holding-the-same-angle/23919/2 "2020-09-17T16:00:31Z")

</div>

In Theory upon firing store the angle in the class and use it in move

Hence change move()
