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.
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.
Thaaat was supposed to be a link. Take 2.
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.
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.
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.
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?
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.
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.
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?
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.
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.
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.
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.