This is quite a tricky question, actually, and I’m not so sure to describe what I need, but I’m attaching a picture that might actually explain it.
I’m creating this third person player controller. Thing is that I’m currently struggling to keep the camera’s behavior when it comes at looking at the player.
I cannot fix the camera on a negative z axis because the camera would not really rotate.
(This is the issue I’m facing if I place the camera at a fixed -z position)
I need to somehow calculate the camera’s position, but avoid fixing it behind the player.
Whenever I open the project in my browser (without having any sort of camera movement setup, and only a lookAt, the camera normally rotates looking at the player and keeping him centered).
(This happens when the camera is not attached and the player moves rightward or leftward, but i need to make the camera follow the player somehow)
The problem is that whenever the player goes forward and rightward at the same time, I have to make the camera move (follow the player), and also look at the player when he is rotating. But this is causing my issues, and the picture describes the issue I’m facing.
How can I create a “follow camera” but keep this rotation?
Is there limitation on using a simple approach such as adding the camera to the character itself or adding both the character and camera to a group and making translations on this group instead of the character?
I agree with @Lawrence3DPK
I would also say that if your working with third person camera, you don’t want it pointing directly at your character, you should rather say camera.lookAt(CharacterVariable.position.x,
CharacterVariable.position.y,
CharacterVariable.position.z + 5)
I thought about this. The thing that confuses me is how to actually position properly the camera and handle its position with the behavior I would want. I certainly cannot link it with a -z against the player.
Check this video for reference:
We can observe here how the camera is not truly fixed to the -z position of the player, since when the player does a circle, the camera remains in the center.
If the camera and character were children of the same common group or camera was parented to the character the camera would simply remain a fixed - z distance in that local space… This is just a suggestion, if there was something preventing you using parenting in this way or you didn’t want to for some other reason you’d have to go about using some sort of calculative approach such as…
const camPos = new THREE.Vector3(0,0,0)
const direction = new THREE.Vector3(0, 0, -1);
var offset
//loop function
direction.set(0,0,-1)
direction.applyQuaternion(character.rotation);
offset = direction.multiplyScalar(-20);
campos.copy(character.position).add(offset);
camera.position.copy(camPos);
camera.lookAt(character.position);
I tried the suggestion of the calculation, but I don’t think it makes the cut.
I’m handling the camera’s position with an object in the group, problem is that still positioning the object inside the group seems to not really work for me - it has to be calculated. I need to somehow calculate for the position in quite a particular fashion.
You cant try visiting the reference project: https://coastalworld.com it might give you an idea on what I mean.
I think what you’re asking for is a “spring arm” implementation of a third-person camera. You should be able to achieve this by not directly attaching the camera to the player, but instead implement a linear interpolation from the camera to the player position. Make sure that the camera follows the player on a fixed speed, independent of framerate. SimonDev made a YouTube video about this a while ago that gives some good pointers.
I can’t find an implementation online of a “spring arm” per-se, but the default Third-Person game template from Unreal Engine has a very nice controller that does implement this. Once you see this, it shouldn’t be that hard to implement by yourself.
P.s.: Don’t make the mistake of having the center-point of the camera focus on the back of your player character model, or the back of its head. Instead, proper third-person cameras are positioned “over the shoulder”. The player (you) should ‘focus’ on what the character sees, not its rear end
Depending on the type of game you’re making, you could implement a key-binding that swaps the camera position between the left and right shoulder to give players some freedom. Some good games to take inspiration from when it comes to Third-person gameplay is “The Division” or the “Tomb Raider” games. I suppose Assassins Creed does a good job as well. In fact, there are a lot of good ones out there these days
Hey, Harold! You actually might be quite right on this one!
I’m trying to create the coastalworld.com third person controller. I think I got the movement right by now, just the camera is left to be done.
Ill check the video you recommended.
If you have not checked the project im using as a reference, and if its not much trouble, i’d appreciate you checking it just in case you get another idea.
Meanwhile ill get my hands on the spring arm to see how it works.