Character and ChaseCamera issue [ Resolved ]

Hi everyone ,



I’ve made a chasecamera with a thirdpersoncharacter ( spatial model not the handler lib) , and i got a little issue .



My goal : when the camera is turned the character is following the direction of the camera like this :



====> O —> ( with ===> the camera O the character and → the direction the character is going )



I did it well , but the problem is by turning the model :



The model is turning well following the camera movement but only between 2 angle , the rest of time it turning on a strange way …



Here a sample of the code :



[java]

if(name.equals(“MoveForward”)){

chara.move(0.005fc.x,0,0.005fc.z);

System.out.println("Cosinus : "+FastMath.cos(rotation));

charadir.fromAngleAxis(FastMath.cos(rotation)+FastMath.PI, new Vector3f(0,1,0));

chara.setLocalRotation(directionperso);

updateCamera();

}





private void updateCamera(){



float hDistance = distance * FastMath.sin((FastMath.PI/2) - vRotation);

Vector3f pos = new Vector3f(hDistance * FastMath.cos(rotation), distance * FastMath.sin(vRotation), hDistance * FastMath.sin(rotation));

pos = pos.add(chara.getLocalTranslation());

cam.setLocation(pos);

cam.lookAt(chara.getLocalTranslation(), initialUpVec);





}

[/java]



My question is :



What am i doing wrong ? i guess it’s related to quaternion but i’m not sure … Thanks in advance ,



Regards ,



Danath

Come on :slight_smile: Someone must have the answer :wink: !

Ouh, you bumped your post, now its not in the “unreplied” filter anymore. Fail xD Also I doubt anyone will make much sense of your code since half of the variables are missing.

damn you’re so right … i’ll do this tomorow ( french time ) thanks a lot !

Something is strange with your code



charadir.fromAngleAxis(FastMath.cos(rotation)+FastMath.PI, new Vector3f(0,1,0));

chara.setLocalRotation(directionperso);



What is the directionperso variable?



Anyway an easier way of doing this is to use the direction of the camera and the quaternion LookAt method



charadir.lookAt(cam.getDirection(),Vector3f.UNIT_Y);

chara.setLocalRotation(directionperso);



Assuming that charadir is a quaternion.

Note that the LookAt method of a quaternion use a direction and not a position like the camera lookAt method.



Btw why don’t you use the JME3 ChaseCamera?

You can find how to achieve this exact behavior in the TestWalkingChar test case. It also handles physics, and i guess that you eventually come to add physics to your game.

sorry directionperso is charadir i forgot to translate for you guys lol



i’m going to test that immediatetly thanks .



JME Chase Camera is not what i want exactly i didn’t find out how to modify it , anyway i’m too close of what i want now to use the JME camera thanks thought :wink:



edit : “Note that the LookAt method of a quaternion use a direction and not a position like the camera lookAt method.”



Didn’t Knew That !!! Thanks a lot it is working now :wink: ! I love you