Easing with arrow keys!

Hey there…

I can’t seem to figure this out, I’m trying to make easing movement using the arrow keys…!?

Here’s what I’m working with:

[AS]
speed = 20;
MC.onEnterFrame = function() {
if (Key.isDown(Key.UP)) {
rotrad = MC._rotation/57;
ymove = speedMath.sin(rotrad);
xmove = speed
Math.cos(rotrad);
_x += xmove;
_y += ymove;
}[/AS]

Any help would be awesome :smiley:

Sorry I’m kind of confused, what are you actually trying to do? What do you mean by “easing movement”? It could mean a variety of things…

Oh yeah, it’s probably better to use a fairly accurate number to convert radians, ie. 57.296(at least) instead of 57

Keep working at it! :slight_smile:

-EG

http://www.kirupa.com/developer/mx/gamecontrols.htm
http://www.kirupa.com/developer/actionscript/gravity.htm

Sorry I’m kind of confused, what are you actually trying to do?

OK - sorry if I was in a bit of hurry!.. Heres the deal: I’m moving a movieclip around the stage using the arrow keys - BUT when I release a key, the movement stops suddently, whats I want it to do is, to like ease out on release, to give a more smooth motion!

… hope you can see where I’m going!

Something like this (copy/paste)

this.createEmptyMovieClip ("ball", 0);
ball.lineStyle(10, 0, 100);
ball.lineTo(.45, .15);

ball.onEnterFrame = function () {
	// Courtesy of Senocular
	this.vx += (Key.isDown(Key.RIGHT)-Key.isDown(Key.LEFT));
	this.vy += (Key.isDown(Key.DOWN)-Key.isDown(Key.UP));
	// To decrease the speed
	this.vx *= .96;
	this.vy *= .96;
	// To move the darn thing
	this._x += this.vx;
	this._y += this.vy;
}

You could also set a maximum speed so that it doesn’t just zoom out of the screen.

pom :slight_smile:

YES - there it is! :s: THX Pom!

Now I just need to figure out how to aply _rotation to the Key.LEFT and Key.RIGHT… but I think I can manage that! Unless you offcause would submit a suggestion :smiley:

I would love to, but I don’t understand what you’re doing with your first piece of code… :slight_smile:

hehe… OK!
Here a allmost working example of what I’m working with - the only thing missing is the easing movement! :-\

See attached .fla

Just port the motion outside the if statements, and throw in the decelaration code :slight_smile:

speed = 10;
MC.onEnterFrame = function() {
	with (this) {
		if (Key.isDown(Key.UP)) {
			rotrad = MC._rotation/57;
			ymove = speed*Math.sin(rotrad);
			xmove = speed*Math.cos(rotrad);
		}
		if (Key.isDown(Key.DOWN)) {
			rotrad = MC._rotation/57;
			ymove = -(speed/5)*Math.sin(rotrad);
			xmove = -(speed/5)*Math.cos(rotrad);
		}
		_x += xmove;
		_y += ymove;
		xmove *= .96;
		ymove *= .96;
		if (Key.isDown(Key.RIGHT)) {
			i = MC._rotation+10;
			setProperty(_root.MC, _rotation, i);
			rot = MC._rotation;
		}
		if (Key.isDown(Key.LEFT)) {
			z = MC._rotation-10;
			setProperty(_root.MC, _rotation, z);
			rot = MC._rotation;
		}
	}
}

By the way, if you’re using with (MC), which means in fact with (this), you don’t have to write MC (or this) in your code later…

pom :slight_smile:

OFFCAUSE!.. THX you so much for your time and help - thumbs up m8! :slight_smile:

You’re welcome :stuck_out_tongue: