Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 11-02-2010, 03:58 PM   #1
Registered User
Join Date: Sep 2007
Posts: 44
Default line hitting moving target

I'm drawing a laser fired from a ship like this:

 //endPoint = ending X value of line(right edge of stage)
 //shipX & shipY = laser start coordinates(starts from ship location)
 this.graphics.lineStyle(1, 0X0000FF); 
 this.graphics.moveTo(shipX, shipY);   
 this.graphics.lineTo(endPoint, shipY);
It fires from left to right.

I also have moving targets on my stage that move from right to left.

Is there any property or method I could use to check the X & Y coordinates of my laser(line) to see if its "hit" a target?

Somehow, I need to get the X value of the laser, and see if it equals the first X value of the target that it encounters. If they equal, then I have a "hit".

Any thoughts or ideas on how to best accomplish this?

cmt9000 is offline   Reply With Quote
Old 11-03-2010, 01:12 PM   #2
Senior Member
Join Date: Feb 2008
Posts: 387

1) for each target in the array: check if laser.x==target[i].x
2) make the laser into a sprite, and simply hitTest that against the targets with shapeflag on.
My Site :- http://blog.bluemagica.com

I need a spriter, and a story writer for arcade fighter and a side-view RPG. If you can help, please pm me!
bluemagica is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 07:41 AM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.