Thanks I searched some stuff on the internet, and indeed i had to attach it first instead of placing the movieclip on stage :)
thanks for helping, nice signature to.
you seem pretty good at actionscript :D
No problem, and thanks.
do you, maybe, know how i move movieclip1 with a certain speed towards movieclip 2?
(i want to use it for the zombies moveing towards the player)
The best way I know of for moving a movieClip towards another is by using Trig. There is a simpler way, where you compare the differences in their locations and move their _x/_y static amounts, but it looks blocky and is confined to 8-direction movement. Using Trig allow for the "zombie", in this case, to move in 360+ directions, and turn to face the player.
If you've covered trigonometry in your Math class, this should be fairly simple once you see how it applies to movement. If you haven't, you may want to google "basic trigonometry" and read up a little. Or, I guess you could just nod-and-smile and use it anyways ;)
The three primary functions of Trig are sine, cosine, and tangent (written as sin(), cos(), and tan(); respectively). These functions are based on a right-triangle, which for our purposes, will be inscribed in a unit circle (circle with a radius of 1).
cosine of some angle, Θ (pronounced "theta"), is the length of the horizontal leg of the right triangle; and sine of Θ (which is the variable used to represent angles) is the length of the vertical leg of the triangle. So, if we can create a triangle with a hypotenuse pointing towards the other movieClip, the width/height of its legs will be the distances the movieClip needs to move in the _x/_y directions to move closer to it. By changing the length of the hypotenuse itself, we can determine how much of a step it is taking.
So:
sin(Θ)=change in _x
cos(Θ)=change in _y
length of hypotenuse=magnitude/speed of change
But, how do we find Θ? By using an
inverse trig function, where you pass the x/y values to get theta, as opposed to passing theta to get x/y. Inverse trig functions are represented by a "-1" after their name, or by prefixing them with "arc".
This is where tangent comes in. tan(Θ) is equal to y/x, so doing arctan(y/x) would equal Θ.
I have to go to class in a few more minutes, so here's where you end up:
//On the Zombie's Actions panel, inside it's onEnterFrame handler
onClipEvent(enterFrame) {
var Theta:Number = Math.arctan((_root.Player._y-this._y)/(_root.Player._x-this._x));
var Speed:Number = 7;
var cx:Number=Math.cos(Theta)*Speed;
var cy:Number=Math.sin(Theta)*Speed;
_x+=cx;
_y+=cy;
}
I'm pretty sure that's it, but I don't have access to Flash and I'm in a bit of a hurry. If it seems flipped in the vertical direction, try flipping "_root.Player._y-this._y" in the Theta calculation.
I'll be back in 3 hours if it doesn't work.