Inertia and rotation

  • Jimmers
  • Born
  • Born
  • Jimmers
  • Posts: 2

Post 3+ Months Ago

Hello.

I'm new to Actionscript and thus totally clueless.

I've got a shape that rotates to follow the mouse.. which looks cool. The problem I've got is that I want to introduce some sense of inertia to it to make it seem more real.

The code as it stands (which, I must confess, I just adapted from some other example I tripped over) is as follows:
Code: [ Select ]
onClipEvent(load){
X = this._x;
Y = this._y;
}
onClipEvent(mouseMove){
Xm = _parent._xmouse;
Ym = _parent._ymouse;
Xdiff = Xm - X;
Ydiff = Ym - Y;
radAngle = Math.atan2(Ydiff , Xdiff);
this._rotation = radAngle*360/(2*Math.PI);
updateAfterEvent();
}
  1. onClipEvent(load){
  2. X = this._x;
  3. Y = this._y;
  4. }
  5. onClipEvent(mouseMove){
  6. Xm = _parent._xmouse;
  7. Ym = _parent._ymouse;
  8. Xdiff = Xm - X;
  9. Ydiff = Ym - Y;
  10. radAngle = Math.atan2(Ydiff , Xdiff);
  11. this._rotation = radAngle*360/(2*Math.PI);
  12. updateAfterEvent();
  13. }

It works well, but I'd just like to see the shape accelerate/decelerate more slowly.

Thanks
  • digitalMedia
  • a.k.a. dM
  • Genius
  • User avatar
  • Posts: 5149
  • Loc: SC-USA

Post 3+ Months Ago

Hey Jimmers!

Please use the
Code: [ Select ]

tags when posting code snippets. I changed your original post. ;)

Thanks.
  • Jimmers
  • Born
  • Born
  • Jimmers
  • Posts: 2

Post 3+ Months Ago

Oh, oops. Sorry. n00bs perogative, that's what that is.

Any idea how to do what I'm after, though? I'm assuming I want some kind of loop, but I just can't seem to see it straight.
  • digitalMedia
  • a.k.a. dM
  • Genius
  • User avatar
  • Posts: 5149
  • Loc: SC-USA

Post 3+ Months Ago

No worries on the code tags. :)

I'm not really in a good place for looking at code (bout to fall asleep) but I would look at using the "onEnterFrame" event so the script fires with each frame, then calculating only a fraction of the mouse location to perform the rotation.

Does that make any sense? It looks like it strictly follows the mouse right now. I'll take another look tomorrow. Sorry, I'm really out of it.

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 9 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.