View Full Version : Shooting
KIERIOSHIMOTO
July 5th, 2005, 07:16 AM
hey, ive read heaps of shooting tuts but cant find one where the bullet moves whichever way the mc faces any help?
nathan99
July 5th, 2005, 07:19 AM
http://www.kirupa.com/forum/showthread.php?t=181368
KIERIOSHIMOTO
July 5th, 2005, 07:35 AM
thanx ill try it
KIERIOSHIMOTO
July 5th, 2005, 07:48 AM
alright, ive worked something out but can someone take a look at my code? my guys instace name is guy and my bullets is bullet
my code wont work
fscommand("fullscreen", "true");
speed = 5;
bulletNo = 0;
//i like to put everything into a holder clip, because if we want to remove all
//clips just say _root.empty.removeMovieClip() instead of using lots of for loops
_root.createEmptyMovieClip("empty", 10);
_root.onMouseDown = function() {
ang = getAngle();
_root["empty"].attachMovie("bullet", "bullet"+bulletNo, 1000+bulletNo);
var bullet = _root.empty["bullet"+bulletNo];
//puts it in some position as p1
bullet._x = guy._x;
bullet._y = guy._y;
bullet.angle = ang;
bulletNo++;
};
_root.onEnterFrame = function() }
//as the earlier bullets are removed, ie _root.empty["ball"+0] etc
//this for loop will get larger and larger, so u might have to use
//arrays etc, but this will work
for (var i = 0; i<bulletNo; i++) {
var bullet = _root.empty["bullet"+i];
//this just moves the ball according to the angle, simple trig
bullet._y -= speed*Math.cos(bullet.angle*(Math.PI/180));
bullet._x += speed*Math.sin(bullet.angle*(Math.PI/180));
if(bullet._x <0){
bullet.removeMovieClip();
}
if(bullet._x > 550){
bullet.removeMovieClip();
}
if(bullet._y <0){
bullet.removeMovieClip();
}
if(bullet._y > 400){
bullet.removeMovieClip();
}
}
};
//i like this formula better for finding the angle than the one u used
function getAngle() {
var delta_x = p1._x-_root._xmouse;
var delta_y = p1._y-_root._ymouse;
var angle = -Math.atan2(delta_x, delta_y)/(Math.PI/180);
return angle;
}
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.