Inertia and rotation

  • Jimmers
  • Born
  • Born
  • No Avatar
  • Joined: Jul 11, 2004
  • Posts: 2
  • Status: Offline

Post July 11th, 2004, 4:45 pm

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
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post July 11th, 2004, 4:45 pm

  • digitalMedia
  • a.k.a. dM
  • Genius
  • User avatar
  • Joined: Dec 29, 2003
  • Posts: 5169
  • Loc: SC-USA
  • Status: Offline

Post July 11th, 2004, 5:49 pm

Hey Jimmers!

Please use the
Code: [ Select ]

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

Thanks.
- dM
  • Jimmers
  • Born
  • Born
  • No Avatar
  • Joined: Jul 11, 2004
  • Posts: 2
  • Status: Offline

Post July 11th, 2004, 6:23 pm

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
  • Joined: Dec 29, 2003
  • Posts: 5169
  • Loc: SC-USA
  • Status: Offline

Post July 11th, 2004, 6:52 pm

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.
- dM

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 41 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
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.