Game Development Reference
In-Depth Information
rJoint.localAnchorA.Set(-20/worldScale,15/worldScale);
revoluteJoint=world.CreateJoint(rJoint) as
b2RevoluteJoint;
return body;
}
Let's look at the new lines:
rJoint.enableMotor=true;
enableMotor
is a Boolean property of
b2RevoluteJointDef
, the joint
definition, and it's a flag to enable joint motor. Its default value is
false
,
but setting it to
true
will allow us to add a motor to the revolute joint.
rJoint.maxMotorTorque=1000;
The
maxMotorTorque
property defines the maximum torque the motor can
apply. The higher the value, the more powerful the motor. Please notice
maxMotorTorque
does not control motor speed, but the maximum torque
applicable to reach the desired speed. It's measured in newton meter or N m.
Finally, the
motorSpeed
property sets the desired motor speed, in radians
per second:
rJoint.motorSpeed=5;
3.
In the end, the three motor related lines mean: enable the motor and set its
speed to
5
radians per second, using a maximum torque of
1000
N m.
4.
Test the movie, and look at your truck running to the right.
Now you can make the truck move. What about moving the truck with a
keyboard input?