jerry
December 27, 2003, 10:35pm
1
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
system
December 28, 2003, 5:31am
2
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
system
December 28, 2003, 11:32am
4
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!
system
December 28, 2003, 11:52am
5
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
system
December 28, 2003, 12:02pm
6
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
system
December 28, 2003, 10:23pm
7
I would love to, but I don’t understand what you’re doing with your first piece of code…
system
December 28, 2003, 10:31pm
8
hehe… OK!
Here a allmost working example of what I’m working with - the only thing missing is the easing movement! :-\
See attached .fla
system
December 28, 2003, 10:43pm
9
Just port the motion outside the if statements, and throw in the decelaration code
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
system
December 28, 2003, 10:48pm
10
OFFCAUSE!.. THX you so much for your time and help - thumbs up m8!