Game Development Reference
In-Depth Information
8. We create one of the arms by placing it at the same location as that of the torso
and giving it a size of
Vector3f(0.25f, 0.25f, 2f)
, making it stretch
out sideways, as shown in the following code snippet:
leftArm = new Geometry("Left Arm", new Box(0.25f,
0.25f, 2f);
RigidBodyControl leftArmRigidBody = new
RigidBodyControl(new BoxCollisionShape(...), 1f);
...
leftArmRigidBody.setPhysicsLocation(new Vector3f(0,
4.25f, 0));
9. We create another
SixDofJoint
for it using the pivot points of
Vector-
3f(0, 2.5f, 0.25f)
and
Vector3f(0, 0, -2.5f)
, offsetting it some
distance to the side of the torso's spatial.
10. Then, we set the angular limits of the joint to
Vector3f(0, 0, 0)
and
Vector3f(FastMath.QUARTER_PI, 0, 0)
.
11. We repeat the previous three steps to create the opposite arm, but we'll reverse the
offset values to make the arm protrude in the opposite direction of the torso.
We now have the basics done for our recipe. Running it should show the character slump-
ing to one side with the arms stretched out to the sides. Now, we can begin with balancing
by performing the following steps:
1. We create a new class called
BalanceControl
, extending
AbstractCon-
trol
.
2. It should have a
SixDofJoint
field called
joint
and a
RotationalLim-
itMotor
field called
motorX
.
3. Create a
setJoint
method.
4. Inside this method, after setting the joint, we also populate
motorX
with one of
the
RotationalLimitMotor
instances, as follows:
motorX = joint.getRotationalLimitMotor(0);
5. Inside the
controlUpdate
method, we get
bodyA
from the joint and store it
in
PhysicsRigidBody
. This is the torso:
PhysicsRigidBody bodyA = joint.getBodyA();