Hi,
I have the following code:
public class ChaseCameraState extends BasicGameState {
private Camera cam;
private ChaseCamera chaser;
// Moving Box
private TriMesh box;
public ChaseCameraState(Camera cam) {
super("ChaseCameraState");
this.cam = cam;
init();
}
private void init() {
loadCurves();
initKeyBindings();
}
private void initKeyBindings() {
KeyBindingManager.getKeyBindingManager().set("toggle_fly", KeyInput.KEY_F);
}
@Override
public void update(float tpf) {
super.update(tpf);
if (chaser != null)
chaser.update(tpf);
if (KeyBindingManager.getKeyBindingManager().isValidCommand("toggle_fly", false)) {
setTarget(box);
rootNode.updateRenderState();
}
}
public void setTarget(Spatial target) {
if (chaser == null) {
HashMap<String, Object> props = new HashMap<String, Object>();
// props.put(ThirdPersonMouseLook.PROP_MINROLLOUT, "3");
// props.put(ThirdPersonMouseLook.PROP_MAXASCENT, "" + 45 * FastMath.DEG_TO_RAD);
// props.put(ChaseCamera.PROP_INITIALSPHERECOORDS, new Vector3f(5, 0, 30 * FastMath.DEG_TO_RAD));
chaser = new ChaseCamera(cam, target, props);
chaser.setWorldUpVec(new Vector3f(0, 0, 1));
// chaser.setMaintainAzimuth(true);
// chaser.setDampingK(0);
// chaser.setStayBehindTarget(true);
chaser.getMouseLook().setEnabled(false);
chaser.setMaxDistance(4);
chaser.setMinDistance(4);
chaser.getMouseLook().setMaxRollOut(0);
chaser.getMouseLook().setMinRollOut(0);
} else {
chaser.setTarget(target);
}
}
private void loadCurves() {
// create control Points
Vector3f[] points = new Vector3f[3];
points[0] = new Vector3f(70, -59, 52);
points[1] = new Vector3f(30, -30, 46);
points[2] = new Vector3f(-50, 0, 40);
BezierCurve curve = new BezierCurve("Curve", points);
box = new Quad("das", 1, 1);
box.setModelBound(new BoundingSphere());
box.updateModelBound();
box.setLocalTranslation(new Vector3f(points[0]));
CurveController cc = new CurveController(curve, box);
box.addController(cc);
cc.setAutoRotation(true);
cc.setRepeatType(Controller.RT_CLAMP);
cc.setUpVector(new Vector3f(0, 0, 1));
cc.setSpeed(0.5f);
this.getRootNode().attachChild(box);
this.getRootNode().attachChild(curve);
}
}
My goal is that the camera follows the quad, but at reaching the end of the line not to turn around.
So backwards the camera looks at the same direction like forwards. Tried alot of the things you
see in the code. But nothing works, any ideas?