Hi again :), I have spent some time working further on the game. I’m running into a couple of issues still related to this topic.
The Dynamic Anim Control is shown here: (maybe important, I load the bird with its controls directly from a j3o file).
BirdControl - DAC
package jmeanimator.models;
import com.jme3.anim.AnimComposer;
import com.jme3.bullet.PhysicsSpace;
import com.jme3.bullet.RotationOrder;
import com.jme3.bullet.animation.*;
import com.jme3.bullet.objects.PhysicsRigidBody;
import com.jme3.math.Vector3f;
import jmeanimator.controls.Face;
public class BirdControl extends DynamicAnimControl implements Face {
enum Action {
FLYING ("Bird.Wingclap");
String actionName;
Action (String actionName) {
this.actionName = actionName;
}
}
private static float MAX_SPEED = 13f;
Vector3f velocity = new Vector3f();
private boolean isInitialized = false;
private Action currentAction = Action.FLYING;
private Action latestActivatedAction = null;
public BirdControl () {
LinkConfig hull = new LinkConfig(1f, MassHeuristic.Density,
ShapeHeuristic.VertexHull, new Vector3f(1f, 1f, 1f),
CenterHeuristic.Mean, RotationOrder.XZY);
super.setConfig(torsoName, hull);
super.link("TailEnd", hull,
new RangeOfMotion(0f, 0f, 0f, 0f, 0f, 0f));
super.link("Head", hull,
new RangeOfMotion(0f, -0.58f, 0f, 0f, 0f, 0f));
super.link("Wing1.R", hull,
new RangeOfMotion(0.26f, 0f, 0f, -0.52f, 1.05f, 0f));
super.link("Wing2.R", hull,
new RangeOfMotion(0.26f, 0f, 0.26f, 0f, 0.26f, -0.35f));
super.link("Tail", hull,
new RangeOfMotion(0f, -0.02f, 0.52f, -0.31f, 0f, -0.07f));
super.link("Back", hull,
new RangeOfMotion(0f, 0f, 0f, 0f, 0f, 0f));
super.link("Neck", hull,
new RangeOfMotion(0.26f, 0f, 0f, 0f, 0f, 0f));
super.link("Wing1.L", hull,
new RangeOfMotion(0.26f, 0f, 0.52f, 0f, 0f, -0.94f));
super.link("Wing2.L", hull,
new RangeOfMotion(0.26f, 0f, 0f, -0.35f, 0.26f, -0.26f));
}
@Override
public String faceCenterSpec() {
return null;
}
@Override
public Vector3f faceDirection(Vector3f storeResult) {
return null;
}
@Override
public void prePhysicsTick(PhysicsSpace space, float timeStep) {
super.prePhysicsTick(space, timeStep);
this.getTorsoLink().getRigidBody().getLinearVelocity(velocity);
if (velocity.length() > MAX_SPEED) {
this.getTorsoLink().getRigidBody().setLinearVelocity(velocity.normalize().mult(MAX_SPEED));
}
}
@Override
public void physicsTick(PhysicsSpace space, float timeStep) {
super.physicsTick(space, timeStep);
if (!isInitialized) {
super.setMass(this.findLink("Torso:"), 20f);
BoneLink neck = this.findBoneLink("Neck");
super.setMass(neck, 5f);
this.setDynamicSubtree(neck, new Vector3f(0f, 100f, 0f), false);
this.getTorsoLink().getRigidBody().setAngularDamping(0.5f);
this.getTorsoLink().setDynamic(new Vector3f(0, 0f, 0));
for (PhysicsRigidBody rb : this.listRigidBodies()) {
rb.setCcdMotionThreshold(0.1f);
rb.setCcdSweptSphereRadius(0.1f);
}
isInitialized = true;
}
}
@Override
public void update(float tpf) {
super.update(tpf);
if (currentAction == Action.FLYING && latestActivatedAction != Action.FLYING) {
AnimComposer animComposer = this.getSpatial().getControl(AnimComposer.class);
animComposer.setCurrentAction(Action.FLYING.actionName);
animComposer.setGlobalSpeed(5f);
latestActivatedAction = Action.FLYING;
}
}
}
Nonetheless I’m really content with the provided tools and framework. Here’s a small preview of flying a bird
https://youtu.be/EYA_45gtEfw