00:00
00:00
Newgrounds Background Image Theme

Zombiehit just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Acceleration/Dece leration?

866 Views | 12 Replies
New Topic Respond to this Topic

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.

Response to Acceleration/Dece leration? 2012-05-02 12:44:15


Thaaat was supposed to be a link. Take 2.

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.

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.

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.

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?

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.

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.

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?

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.

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.

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.

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.