View Full Version : [AS2]Help with falling object and movement

05-12-2011, 11:38 AM
Hi everyone. So I am making a game in flash using actionscript 2. The idea is that there are several lines of moving objects and if you press space you release an object and it has to fall on the moving object below that one and the objects have to stack. I haven't used a lot of actionscript so don't really know how to do this, was using this code:

onClipEvent(enterFrame) {
speed = 5;
this._x +=speed;
//This should be for the object to fall straight through Y
if (Key.isDown(Key.SPACE)){
this._x -= speed;
this._y += 10;
//This should be for the falling object to move with the moving object below it
this._x -= 7;
this._y -= 10;

But obviously it doesn't work. First I would like that I don't have to leave Space pressed for the falling of the object to continue (have to leave it pressed or the object continues moving through X). Also When it hits the "torso" it will pretty much go around it and won't really follow it so wanted to know how to do this as well.

So basically I would like to know how to use space for the object to keep falling and not keep it pressed and how to make an object stack on the other and follow it.

Thanks everyone for your time and would be really thankful if you can help me.

P.S: Sorry for so much text

05-12-2011, 09:45 PM
I see you have a "speed" variable. What if you had separate xSpeed and ySpeed variables?

05-13-2011, 01:07 AM
That shouldn't change much from the code I have. I could just remove speed and add a 5 instead, that variable is pretty useless as I see it, still thanks for trying to help.
If anyone has another advice or a way to help I will be very grateful.

05-13-2011, 03:20 PM
I mean, like, if you give it a ySpeed and change its value when you press down, that would help with your goal of not having to leave the key pressed.

For stacking, you could give them an "ontop" variable or something that stores what is on top of it. Like, when A lands on B, then you assign B.ontop = A Then when you move B check if B.ontop!=null and if it's non-null then you move it and check its ontop value in turn, and keep going up the chain of ontops until you reach the one that's still null, which is the one that doesn't have anything ontop of it.