# Help with particles heading to target

**URL:** <https://forum.kirupa.com/t/help-with-particles-heading-to-target/197561>\
**Category:** Uncategorized\
**Created:** [August 17, 2006, 1:14pm UTC](https://forum.kirupa.com/t/help-with-particles-heading-to-target/197561 "2006-08-17T13:14:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![steviespin](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/steviespin/32/657_2.png) [@steviespin](https://forum.kirupa.com/u/steviespin)\
**Post date:** [August 17, 2006, 1:14pm UTC](https://forum.kirupa.com/t/help-with-particles-heading-to-target/197561/1 "2006-08-17T13:14:20Z")

</div>

Hey!

I got the following code online to make particles head to a specific location on screen. I can’t get it to work, though, because i’m not sure where to put which part of the script. (ie on timeline or movieclip).

i can’t get it to work.

can anyone help out? the script might be useful to others too!

thanks!  
S

speed =20;

target\_x= //some number  
target\_y= //some number

tanx= target\_x-this.\_x;  
tany= target\_y-this.\_y;  
radangle = Math.atan2(tany,tanx);  
this.\_rotation = radangle\*180/Math.PI; // this is to point it in the right direction if you need to  
deltay = speed \* Math.sin(radangle);  
deltax = speed \* Math.cos(radangle);

function bombTarget(){  
if(deltax\<0){  
if(target\_x \< this.\_x){  
this.\_x += deltax;  
this.\_y += deltay;  
}  
if(this.\_x \<= target\_x ){  
bombing = false;  
gotoAndPlay(2);  
}

```
	}
	if(deltax&gt;0){
		if(target_x &gt; this._x){
			this._x += deltax;
			this._y += deltay;
		}
		if(this._x &gt;= target_x){
			bombing = false;
			gotoAndPlay(2);
		}
		
	}

```

}

i have the function as bombtarget but you can change it to whatever you want.

onClipEvent(enterFrame){  
if(bombing){  
bombTarget();  
}  
}
