I’m trying to implement First Person Shooter camera.
FPS camera is something that stays around the forehead of the character model (and bone) (track the head’s position and move together), and it rotates as the head rotates.
Or I should say that the head follows the rotation of the FPS camera.
(In this case, the model keeps standing and only rotates its head to see the world around him).
I thought of using Universal Camera and a Bone that is embedded in the head mesh, and synchronize rotations of these two.
But I am not sure which properties of camera and bone should be linked.
And axis (local or world?) matter is also confusing.
I’m using a model (and texture) from this example.
This Multi View method would help you to compare TPS and FPS.
If you could help me I really appreciate it!
Thank you for reading.
miyabi
Parenting looks cool, but is it possible to parent a camera to a bone?
I tried it, but it seems not working.
If you have nailed it, would you show me a code?
But Ideally if its first person you would attack your mesh to your camera and play animations in response to your inputs.
https://www.babylonjs-playground.com/#11BH6Z#447
You will need to hide certain parts of your mesh to the camera though, like hide the head and move the camera forward from center slightly. You gotta consider what the person will actually “see” from first person.
So the main stuff you gotta worry about is the height of the model add some sort of simple physics impostor or bounding box/capsule setup. Then attach the camera to that. Then you will need to tailor your mesh and animations for FPS.
Any sort of sway can be a simple cos/sin addition to the cameras rotation specific axes scaled by the magnitude of some factor like the speed of the player.
Wow this looks great!
This dynamic fov control must be very useful when you move around the world, but in my case, models just sit and only move their upper body to see the world around them, so I might not employ your great method to my app.
But thanks for showing me pretty good demo!
Offset the local position of the camera forward so that the view does not feel like it is in the head of the model, or hide the head (don’t know if this is possible).
That is exactly what I am trying to solve.
I think, to properly make the camera stay exactly the same position relative to the head (maybe on the forehead of the model), the camera need to move inside the local space of the head (actually the neck bone).
So I want the camera to use the local space of neck bone as its world space.
Not necessarily, in fact it might cause jittery jumpy movements, and you are gonna have to constantly update your up vector anyways on the camera.
Re read my post about the height and animations reliant on basic math.
A simple solution given what you would want to lerp the cameras position to the bones absolute position. But then you are gonna have to figure out a way to establish forward.
Thank you for your replys Pryme8!
I like the way how universal camera rotates as I keep clicking on the canvas and move the cursor around.
The distances that the cursor’s moved along x (and y) axis from the position of mouse-on event affects the camera’s rotation around y (and x)
Do I need to implement this distance-to-rotation conversion by myself (which I think I can but not the best at)?
So the solution would be
Make the camera a child of the head mesh which is attached to the neck bone.
So the parent->child relationships becomes [neck bone]->[head mesh]->[fps camera(not universal camera anymore)].
Implement the cursor’s-moved-distance-to-rotation-around-x-and-y-axis conversion by myself, and use that calculated rotation to rotate the neck bone.
But why? The person in first person will never see it unless you are using a reflection probe and do a mirror or something, but even then I belive convention would be to render a different model to the reflection probe then what you are rendering to the first person camera.
Remember we are only trying to simulate real life models not emulate them.
There is always a creative solution. The main consideration to have here is what is your final product trying to achieve, a realistic biometrics system or just a representation to fool the brain?