Hi!
In my project, I’m trying to make a cinematic which includes a camera travel (this is working fine) and a camera rotation. What is the easiest way to make the camera look at a certain point in space during the whole cinematic travel?
Thank you,
Xavier
There is a cam.lookAt(Vector3f) you can do every frame
edit:
lookAt(Vector3f pos, Vector3f worldUpVector)
I think you can use Vector3f.UNIT_Y as the second argument
Ok, do I put that in simpleUpdate() for it to trigger every frame?
Thanks for the info!
Yes that would work, I have mine in a seperate update method for my “cinematic” which is represented as a class, but ultimately even that is called from the simpleUpdate, so yeah.
Ok, so I’ve done all of this, but the camera still isn’t moving. Here are the important methods:
[/java]
private void initCameraMouvements() {
//mouvement 1
//vecteurs de début/fin
Vector3f debut1 = new Vector3f(0f, 30f, 400f);
Vector3f fin1 = new Vector3f(0f, 30f, -400f);
//place la caméra au début
cam.setLocation(debut1);
cam.lookAt(fin1, Vector3f.UNIT_Y);
//créé le mouvement
MotionPath path1 = new MotionPath();
path1.addWayPoint(debut1);
path1.addWayPoint(fin1);
path1.enableDebugShape(assetManager, rootNode);
//créé la cinematic
cinematic1 = new Cinematic(rootNode, travelTime);
stateManager.attach(cinematic1);
CameraNode camNode = cinematic1.bindCamera("cam1", cam);
camNode.setControlDir(ControlDirection.SpatialToCamera);
cinematic1.activateCamera(0, "cam1");
//ajoute le mouvement à la cinematic
MotionEvent cinematic1MotionControl = new MotionEvent(camNode, path1);
cinematic1MotionControl.setDirectionType(MotionEvent.Direction.Path);
cinematic1MotionControl.setSpeed(1f);
cinematic1MotionControl.setInitialDuration(travelTime);
//ajoute le mouvement à cinematic1
cinematic1.addCinematicEvent(0, cinematic1MotionControl);
//mouvement 2
}
private void cameraRotation(boolean rotate){
if (rotate){
cam.lookAt(new Vector3f(0,0,0), Vector3f.UNIT_Y);
}
}
@Override
public void simpleUpdate(float tpf) {
cameraRotation(rotate);
}
[java/]
And here’s the action listeners for my cinematic.
[/java]
private void initActionListeners() {
cinematic1.addListener(new CinematicEventListener() {
public void onPlay(CinematicEvent cinematic) {
System.out.println(“Mouvement 1 en cours”);
rotate=true;
}
public void onPause(CinematicEvent cinematic) {
}
public void onStop(CinematicEvent cinematic) {
rotate=false;
}
});
}
[java/]
Sorry for some of the French in my code.
Any idea of the problem?
I’ve found the solution, for anyone who might have the same problem.
You just have to change the DirectionType of your cinematicMotionControl to Motion.Direction.LookAt and add this line right before:
cinematic1MotionControl.setLookAt((What you want to be looking at), Vector3f.UNIT_Y);
In the past I have setup 2 paths, one for the camera to follow, and another containing an empty spatial to target the camera to, works nicely
I guess you could even use something like spatial.getLocalTranslation() and then it will always look to the spatials Position, without you needing to update it.
Then you’d put a motion path on that spatial to control the lookat aswell