Game Development Reference
In-Depth Information
6.
The core of the script is written in the updateWorld function, which adjusts
the motorSpeed variable according to the key being pressed (I also simulate
some kind of inertia and friction multiplying it by 0.99 each time), limits
the maximum motor speed to 5 or -5 , and updates the motor speed of the
revolute joints.
private function updateWorld(e:Event):void {
if (left) {
motorSpeed-=0.1;
}
if (right) {
motorSpeed+=0.1;
}
motorSpeed*0.99;
if (motorSpeed>5) {
motorSpeed=5;
}
if (motorSpeed<-5) {
motorSpeed=-5;
}
frj.SetMotorSpeed(motorSpeed);
rrj.SetMotorSpeed(motorSpeed);
world.Step(1/30,10,10);
world.ClearForces();
world.DrawDebugData();
}
7.
The SetMotorSpeed method directly applied on the revolute joint (not on
its definition) allows us to update motor speed on the fly.
8.
Test the movie and you will be able to control the truck with left and right
arrow keys.
 
Search WWH ::




Custom Search