# Easing with arrow keys!

**URL:** <https://forum.kirupa.com/t/easing-with-arrow-keys/38667>\
**Category:** flash\
**Created:** [December 27, 2003, 10:35pm UTC](https://forum.kirupa.com/t/easing-with-arrow-keys/38667 "2003-12-27T22:35:55Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![jerry](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@jerry](https://forum.kirupa.com/u/jerry)\
**Post date:** [December 27, 2003, 10:35pm UTC](https://forum.kirupa.com/t/easing-with-arrow-keys/38667/1 "2003-12-27T22:35:55Z")

</div>

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 = speed_Math.sin(rotrad);  
xmove = speed_Math.cos(rotrad);  
\_x += xmove;  
\_y += ymove;  
}[/AS]

Any help would be awesome 😃

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 28, 2003, 5:31am UTC](https://forum.kirupa.com/t/easing-with-arrow-keys/38667/2 "2003-12-28T05:31:03Z")

</div>

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! 🙂

-EG

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 28, 2003, 8:35am UTC](https://forum.kirupa.com/t/easing-with-arrow-keys/38667/3 "2003-12-28T08:35:39Z")

</div>

[http://www.kirupa.com/developer/mx/gamecontrols.htm](http://www.kirupa.com/developer/mx/gamecontrols.htm)  
[http://www.kirupa.com/developer/actionscript/gravity.htm](http://www.kirupa.com/developer/actionscript/gravity.htm)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 28, 2003, 11:32am UTC](https://forum.kirupa.com/t/easing-with-arrow-keys/38667/4 "2003-12-28T11:32:38Z")

</div>

> 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!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 28, 2003, 11:52am UTC](https://forum.kirupa.com/t/easing-with-arrow-keys/38667/5 "2003-12-28T11:52:51Z")

</div>

Something like this (copy/paste)

```auto
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 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 28, 2003, 12:02pm UTC](https://forum.kirupa.com/t/easing-with-arrow-keys/38667/6 "2003-12-28T12:02:18Z")

</div>

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 😃

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 28, 2003, 10:23pm UTC](https://forum.kirupa.com/t/easing-with-arrow-keys/38667/7 "2003-12-28T22:23:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 28, 2003, 10:31pm UTC](https://forum.kirupa.com/t/easing-with-arrow-keys/38667/8 "2003-12-28T22:31:35Z")

</div>

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

See attached .fla

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 28, 2003, 10:43pm UTC](https://forum.kirupa.com/t/easing-with-arrow-keys/38667/9 "2003-12-28T22:43:03Z")

</div>

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

```auto
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 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 28, 2003, 10:48pm UTC](https://forum.kirupa.com/t/easing-with-arrow-keys/38667/10 "2003-12-28T22:48:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 28, 2003, 10:53pm UTC](https://forum.kirupa.com/t/easing-with-arrow-keys/38667/11 "2003-12-28T22:53:41Z")

</div>

You’re welcome 😛
