I’ve been trawling through the forums looking for some guidance on my problem, but so far seem to be drawing blanks:
Basically, I want to be able to have a gun rotate to follow the mouse, fire in that direction, and be affected by gravity so that the projectile falls back to earth.
So far I’ve managed to get the gun rotating to follow the mouse and fire projectiles in that direction, but the gravity aspect is completely eluding me.
Here’s the code so far:
var speed = 10;
function onMouseMove() {
gun._rotation += Math.atan2(gun._ymouse, gun._xmouse)*180/Math.PI;
updateAfterEvent();
}
function onMouseDown() {
gun.localToGlobal(point);
var bullet:MovieClip = _root.attachMovie("bullet", "bullet_"+_root.getNextHighestDepth(), _root.getNextHighestDepth());
bullet._x = gun._x;
bullet._y = gun._y;
bullet._rotation = gun._rotation;
bullet.onEnterFrame = function() {
this._x += Math.cos(this._rotation*Math.PI/180)*_root.speed;
this._y += Math.sin(this._rotation*Math.PI/180)*_root.speed;
};
}
Has anyone any idea?
Thanks
Slocombe