Reputation: 431
I have been trying to make a 3rd person camera in libgdx for the past couple of days and can't seem to figure out how to do it. I have tried the rotateAround function in PerspectiveCamera, but when I move the camera to be just behind the model its suppose to follow, the rotation gets messed up. I am at a loss at what to try now. I want the camera to be set back and just above the model and to follow it. If someone could point me in the correct direction, I would greatly appreciate it.
Upvotes: 2
Views: 1402
Reputation: 83
In your render method of your game you want to update the camera to follow the player at a distance and you also want to make sure that the camera is looking at the right position either at your character or just ahead if you want to get an over the shoulder view.
Depending on the scale of your models you may have to play around with these values.
In the render loop you want something like this:
note that in this example player is a vector3 and cam is a Perspective camera
This will make the camera look at the character. You may want to modify the values to make it look ahead (Change the x and z for that).
cam.lookAt(player.x, 0, player.z);
Here we set the location of the camera so we can see that it will always be floating behind and above the character
cam.position.set(player.x, 10f, player.y-20f)
This updates the camera to apply all of your transformations
cam.update();
About rotation i'm not too sure, i've not tried it. Heres an article that should help.
Upvotes: 2