## Acceleration/Dece leration?

• 732 Views
• 12 Replies
dylan-double-c
dylan-double-c
• Member since: Mar. 5, 2008
• Offline.
Forum Stats
Member
Level 17
Musician
Acceleration/Dece leration? 2012-05-02 12:43:14

How can I get something to spin faster with the press of a key, and slow down with the release of said key?

My progress/failed attempt.
dylan-double-c
dylan-double-c
• Member since: Mar. 5, 2008
• Offline.
Forum Stats
Member
Level 17
Musician
Response to Acceleration/Dece leration? 2012-05-02 12:44:15

Thaaat was supposed to be a link. Take 2.

MSGhero
MSGhero
• Member since: Dec. 15, 2010
• Offline.
Forum Stats
Supporter
Level 16
Game Developer
Response to Acceleration/Dece leration? 2012-05-02 12:49:18

At 5/2/12 12:44 PM, dylan-double-c wrote: Thaaat was supposed to be a link. Take 2.

Add an increasing number to its rotation.

dylan-double-c
dylan-double-c
• Member since: Mar. 5, 2008
• Offline.
Forum Stats
Member
Level 17
Musician
Response to Acceleration/Dece leration? 2012-05-02 12:51:26

At 5/2/12 12:49 PM, MSGhero wrote:
At 5/2/12 12:44 PM, dylan-double-c wrote: Thaaat was supposed to be a link. Take 2.
Add an increasing number to its rotation.

I'm not quite sure I understand you.

MCarsten
MCarsten
• Member since: Dec. 30, 2009
• Offline.
Forum Stats
Member
Level 21
Programmer
Response to Acceleration/Dece leration? 2012-05-02 12:51:26

Simple math and physics overview. Imagine you have a wheel spinning, the velocity which the angle changes can vary to any number possible, so we can say we have an angular velocity. Although all variable velocities must have a specific acceleration, it would be the angular acceleration. But if we throw this wheel in a polished surface and in a irregular rigid terrain we will notice how faster the velocity will tend to 0, this would be related to the friction.

``````var angularVelocity:Number = 0;
var angularAcceleration:Number = .5;
var friction:Number = .98;

// enter frame....
movieclip.rotation += angularVelocity;
angularVelocity *= friction;

// 1) left pressed, 2) right pressed
// 1)
angularVelocity -= angularAcceleration;
// 2)
angularVelocity += angularAcceleration;``````

Done.

dylan-double-c
dylan-double-c
• Member since: Mar. 5, 2008
• Offline.
Forum Stats
Member
Level 17
Musician
Response to Acceleration/Dece leration? 2012-05-02 12:55:16

At 5/2/12 12:51 PM, Spysociety wrote: Maths.

So my main problem is in my variables and operators?

Or am I misinterpreting that?
MCarsten
MCarsten
• Member since: Dec. 30, 2009
• Offline.
Forum Stats
Member
Level 21
Programmer
Response to Acceleration/Dece leration? 2012-05-02 13:09:58

At 5/2/12 12:55 PM, dylan-double-c wrote:
At 5/2/12 12:51 PM, Spysociety wrote: Maths.
So my main problem is in my variables and operators?
Or am I misinterpreting that?

No, I'm just telling you how to perform your spinning.

Khronosis
Khronosis
• Member since: Mar. 28, 2010
• Offline.
Forum Stats
Member
Level 17
Programmer
Response to Acceleration/Dece leration? 2012-05-02 13:31:02

Acceleration is the change in velocity (for example: meters per second PER SECOND)
Basically what you want is to create one variable "velocity" that will directly add/subtract from the rotation every frame. Then you'll have a variable "acceleration" that will add a small amount to the velocity every frame that the key is held down. And finally you'll have a variable "friction" that will multiply the velocity by something like 0.9 every frame so that the wheel will gradually slow down if the key is released.

I implore you to reconsider.

dylan-double-c
dylan-double-c
• Member since: Mar. 5, 2008
• Offline.
Forum Stats
Member
Level 17
Musician
Response to Acceleration/Dece leration? 2012-05-02 13:58:33

Sweet! Success!
Thanks a whole lot. Correct me if I'm wrong (I don't have Flash on this laptop), but would...

this._x += angularVelocity;

...Get it to roll at the same pace as it's rotation speed?

Sam
Sam
• Member since: Oct. 1, 2005
• Offline.
Forum Stats
Moderator
Level 19
Programmer
Response to Acceleration/Dece leration? 2012-05-02 14:00:53

At 5/2/12 01:58 PM, dylan-double-c wrote: Sweet! Success!
Thanks a whole lot. Correct me if I'm wrong (I don't have Flash on this laptop), but would...
this._x += angularVelocity;
...Get it to roll at the same pace as it's rotation speed?

Yeah, because you're moving it's X position by the same variable as moving the rotation.

MCarsten
MCarsten
• Member since: Dec. 30, 2009
• Offline.
Forum Stats
Member
Level 21
Programmer
Response to Acceleration/Dece leration? 2012-05-02 14:47:08

At 5/2/12 01:58 PM, dylan-double-c wrote: Sweet! Success!
Thanks a whole lot. Correct me if I'm wrong (I don't have Flash on this laptop), but would...
this._x += angularVelocity;
...Get it to roll at the same pace as it's rotation speed?

Yes, just like Sam said, because the same variable of rotation is the same of the velocity. Although this is physically incorrect. The rotation in physics is one of the most complex studies, you actually would have to deal with center of mass (the distribution of mass particles during the translation), moment of inertia (measure how easy you can rotate a body according to its center of mass), angular momentum (measure the distribution of mass in the body according to its angular velocity) and the said above angular velocity.

But of course, you are not going to use these, because they require calculus and further studies. So basically yeah, you can just move your body according to the 'angularVelocity' variable.

milchreis
milchreis
• Member since: Jan. 11, 2008
• Offline.
Forum Stats
Member
Level 26
Programmer
Response to Acceleration/Dece leration? 2012-05-02 15:11:20

At 5/2/12 02:47 PM, Spysociety wrote: The rotation in physics is one of the most complex studies

Yeah, building that fusion reactor was a piece of cake, but these rotating rigid bodies creep the hell out of me.

dylan-double-c
dylan-double-c
• Member since: Mar. 5, 2008
• Offline.
Forum Stats
Member
Level 17
Musician
Response to Acceleration/Dece leration? 2012-05-03 08:01:08

At 5/2/12 02:47 PM, Spysociety wrote: Physics

So that would provide a "spin-out" effect with a bunch of initial rotation, right? Like an RC car on a sheet of ice. I just want to make sure I understand the idea.