17 Replies Latest reply on Apr 17, 2008 7:33 AM by kglad

So I'm creating a game and there's movie clip following my mouse and I want the bullet clip to go through where I clicked, then continue past staying in a straight line the whole time. I will be creating more than one of these "bullets". I can't think of any other way to explain it. but if you go to this game I want my bullets to do the same as theirs. Endless War 3 I hope this explination and code is helpful. I really need help with this and it will be appriciated!
above your onEnterFrame rotate your bullet to the stage's _xmouse,_ymouse and in your onEnterFrame update your bullet's _x and _y properties to move towards _xmouse,_ymouse by using Math.atan(difx,dify), where difx is the difference between your bullet's original (or current) _x property and _xmouse. likewise for dify.
Ok, so here's what I did:

In the player mc I have this code :
onEnterFrame = function()
{
// Calculates the mouse angle in radians
// Converts the mouse angle to degrees so it can be expressed in _rotation terms
this._rotation = myDegrees+90;
// Turns the MC to face the mouse
}

I want my "bullets" to act exactly as the bullets do in this game http://xdesktop.net/play/Endless-War-3.htm.

your bullet's _x property should be updated on each loop to change by bulletSpeed*Math.cos(myRadians) and its _y property by bulletSpeed*Math.sin(myRadians)
quote:

your bullet's _x property should be updated on each loop to change by bulletSpeed*Math.cos(myRadians) and its _y property by bulletSpeed*Math.sin(myRadians)

I really don't understand this dude can you incorporate it into my code? I'm a hardcore begginer and I'm guessing I'm a bit over my head with this one.

:

ok I'll try it out tommarrow I'm still not 100%. Confusing buisness this trig and programming.
make sure you define bulletSpeed.
quote:

make sure you define bulletSpeed.

just a variable right or does it have to do with this?

quote:

above your onEnterFrame rotate your bullet to the stage's _xmouse,_ymouse and in your onEnterFrame update your bullet's _x and _y properties to move towards _xmouse,_ymouse by using Math.atan(difx,dify), where difx is the difference between your bullet's original (or current) _x property and _xmouse. likewise for dify.
quote:

it's just a variable the determines the speed of the bullet.
I tried it and it moves great but it still follows the mouse. I want it to stay on a straight path without wavering becouse I'm going to eventually make it run with 2 or 3 bullets so the first one doesn't get replaced each time. Here's what I did I played with it but I can't get it to stay straight.

create a new bullet everytime bullet() is called and assign myRadians in that function (outside your onEnterFrame loop).
quote:

create a new bullet everytime bullet() is called and assign myRadians in that function (outside your onEnterFrame loop).

That'll make the bullet go straight instead of following the mouse?

make myRadians a property of the bullet. that will prevent the new bullet's direction from influencing any previous bullets.
quote: