Acceleration

I was doing the actionscript tutorial with the beetle and using key’s to make it move in different directions. And I thought I’d try to add some acceleration to it. Well, the only way i knew how to do that was to make the movement exponential instead of just linear. I wrote this code myself, and well I’m a total n00b at actionscript, so sorry if its hideous. Here is what I wrote:

If (this._y < -1)
{
on (keyPress “<Up>”) {
currentY = this._y;
this._y = currentY + .1 * currentY;
_root.bug._rotation = 360;
}
on (keyPress “<Down>”) {
currentY = this._y;
this._y = currentY - .1 * currentY;
_root.bug._rotation = 180;
}
}
I thought I’d need to make it exponential only when the y was >, < 1, so that it wouldn’t exponentialy increase 0 (stay at 0). Yet, it gives me some hideous looking error.

Scene=Scene 1, Layer=beetle, Frame=1: Line 26: Statement must appear within on handler
{

Scene=Scene 1, Layer=beetle, Frame=1: Line 39: ‘)’ or ‘,’ expected

Scene=Scene 1, Layer=beetle, Frame=1: Line 38: Statement must appear within on handler
If (this._y

I know this method would work fairly wierd after the bug stopped moving at like x = 90, and then the key was pressed again and it starts off moving very fast. But, i couldn’t get the actual acceleration tutorial to work. Thanks for all your help guys.

Cheers,
NaliWarCowz :trout:

Well read your error message.

The error is happening because your if statment is confusing Flash.

You can’t have actionscript on a clip without it being inside a handler, and in this case, an on handler.

OH, ok. Sorry, i’m a total flash n00b. So the if statements have to be inside the on(keypress) thing? Ok, i got it now. Sorry for the n00bishness.

No problem man. I hope that solves your problem :slight_smile:

But what I wanna know is… How are you a N00B!? You know Kirupa personally, didn’t his ability rub off on you? :stuck_out_tongue: