Here is a very simple code sample. You will want to adjust it to do
whatever you want.
================================================
// assuming symbol with linked name "bullet" exists in library
// assuming movieclip named "gun" is on stage and its center point
// in the middle of the gun
// length of vector representing the strength at the exit of the gun
gun.strength=10;
// functions that alows the bullet to move
// must be assigned to the bullet as onEnterFrame
// on bullet movieclip when fired
gun.$bulletPath = function() {
this._x += this.dx;
this._y += this.dy;
}
gun.fire = function() {
var d = this._parent.depth++;
var b = this._parent.attachMovie(
"bullet",
"b" + d,
d,
{_x: this._x, _y: this._y}
);
// find direction bullet must take, relative to gun
// by the way you'll need to modify gun's rotation too
var dx = this._parent._xmouse - this._x;
var dy = this._parent._ymouse - this._y;
// calculate ratio of mouse distance relative to strength
var ratio = this.strength / Math.sqrt(dx*dx + dy*dy);
// adjust movement steps for bullet
b.dx = dx * ratio;
b.dy = dy * ratio;
// bullet to start moving
b.onEnterFrame = this.$bulletPath;
}
// on Mouse Down, fire!
// you can call fire from whatever event you like
gun.onMouseDown = gun.fire;
================================================
Tim.
[quoted text, click to view] isthatlegal wrote:
> I am making a platformy style game, and i am wanting to fire a "bullet" from my
> charactor, only i want the bullet to fire towards the mouse cursor...
>
> could sumone please give me the script for this, only with comments, as i wish
> to understnad the script, not just use it..
>
>
> thanks a lot for any help
>
> Dan