View Full Version : [AS3] Firing a bullet at a movieclip
Monsterlag
04-30-2009, 12:29 PM
Hi :D
I have bullets in my game but I want them to be aimed at the player's location and not just travel along x or y. I don't want the bullet to home in on the player but be aimed at the location he was at when the bullet was added (like "fire and forget"). How can I do this? :)
TomMalufe
04-30-2009, 01:15 PM
if you just set a "Target" (x,y) on creation and never update it again you can do it. As long as your bullet exists, that bullet as ONE UNIQUE target point.
Try creating a class for your bullet that extends MovieClip and takes a Point as part of the constructor. Nothing else, unless you feel confident with classes.
Ciubhran
04-30-2009, 04:19 PM
I hope the bullet is an object (created with something like 'new Bullet()').
If it is, just use a TargetX and TargetY when it is shot. Then calculate the angle from the current point to the TargetX and TargetY, then just make it fly in that direction. If you want it to die after X pixels, just make a pixel counter and remove it from the stage when it has reached >=X pixels.
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.