How should I configure the virtual camera on Cinemachine for a First Person?
If you have a better way to do this, just post it ! I’m sure that the Cinemachine team has his own and better way to do this, so please guys, share the how to.
Hi @churi24 It looks like you’re off to a good start RE 1st person shooter. It’s a big topic with a lot of questions, so I’ll do a little brain dump on ideas and learnings I’ve had working in this area.
Don’t make a giant ball of code camera which tries to do everything. Instead use a number of virutal cameras for each different scenario. One for the main 1st person shooter. One for when you sprint (maybe widen the FOV) one for when you go to a scope view (then you have blend controls between them) etc.
Is your gun shooting from the center of the camera’s Z axis or from the weapon? That makes a difference as when you get to walls sometimes the gun and your eye ‘see’ different things
How are you planning to handle camera shakes on explosions / impacts? There’s a few ways to do that. We want to simplify shakes with a new upcoming ‘Impulse’ module which we’re currently developing (no ETA yet, I’m afraid)
Let us know how it goes and what kinds of goals and issues you’re having so we can give specific help
I’m a little lost, that’s why I had created this post.
The camera mechanic of our game is similar to Outlast, RE7, etc. All the interaction occurs from the center of the camera’s Z axis.
The main problem I found here is how to integrate and set up the virtual camera in the head of the character without writing tones of code. We wanna do something similar to Outlast where the player can see his own body.
So the camera should be in the head of the player and controlled by Input.mouse, I think…
The problem when you are moving. This is a video of our game (without Cinemachine), I have been coding some stuffs for a basic camera, but with Cinemachine I want to delete all the scripts and replace them by Virtual Cameras.
In my example when you go from Idle to Walk and from Walk to Run, the camara don’t smooth between animations, so you can notice how it change between states and that sucks.
If I integrate virtual cameras to this, the problem is that I don’t know how to solve the walking, idle and running moves on the virtual camera without coding. The perlin noise is not realistic for a walk or run, or maybe it’s because I don’t know how to configure it… I think it’s better for earthquakes, or when you go inside a car, or something similar to that.
A problem to resolve with Virtual Cameras is the smooth of the movement.
Here in this video the player rotate looking at a tree all the time trying to mantain the tree centered on the camera and moving with W & D while he is running. You can see how the camera shake as if he has a problem with the fps. If I attach the virtual camera to the head of the player I will have this problem, so the virtual camera should follow the player in a smooth way
In conclusion I have this problems: A) How should I integrate and set up the virtual camera, B) How do I solve the problem of idle, walk and run moves.
The last video was recorded using Smart Update. If I use Fixed Update or Late Update works much better, but the shaking still exist, it’s really tiny but exist. I think I made something wrong with the config of the CM.
Camera judder in Unity is very often the result of inconsistent FPS for the moving camera and/or subject. A good way to get an impossibly shaky camera is to mix animation modes: move some things with physics (in FixedUpdate), and others in normal Update. Don’t do that. Try animating everything in FixedUpdate, and see if the judder goes away.
I made some changes… Now I have the camera perfect without judder . I’m testing everything on a clean scene, just a terrain, some trees, the FirstPersonController and Cinemachine.
I’m testing some ideas and I have merged the Update inside the FixedUpdate in the FirstPersonController. Now it goes smooth like a silk and the problem is solved. The new question is, why it’s working now?
It works because Unity guarantees a constant deltaTime in FixedUpdate, but not in Unpdate. Simulations and other things that are sensitive to frame spacing (Cinemachine included) often work better in FixedUpdate.
Ok, so in that case I only have code to move the character. The camara will follow the character using Cinemachine. So in my case the integration of the virtual camera could be solved right now, but I want to hear more options. Now the main problem is How do I solve the problem of idle, walk and run moves with cinemachine?
Have a look at CinemachineStateDrivenCamera. It’s a kind of manager-meta-camera that gives you an interface to map its vcam children to specific animation states within your character. Make Idle, Walk, and Run vcam children. Set them up the way you like. Then map them to the Idle, Walk, and Run animation states of your character using the interface in the SDC’s inspector. The SDC will take care of enabling the right camera at the right time. You can even set up custom blend styles for the transitions. It’s incredibly powerful, and no code is needed.
Yes you are right, but this is the second part, first I need to know how to set up the virtual camera for each state. Perlin Noise for a Walk movement is not a realistic solution unless you know how to config perlin noise for a walk.
I could make a script with a curve to simulate the movement on each state, but this comment prevents me to go on that way…
The question here is how do I config the movement on the virtual camera for idle, walk and run ?
CM examples folder includes some perlin noise presets (e.g. handheld, etc). Try playing with those. Adjust the gain and frequency until it approximates what you want. Then fine-tune the profiles later.
If all else fails, it’s always possible to write a custom noise component for Cinemachine (remember, it’s modular so this is easy - have a look at CinemachineBasicMultiChannelPerlin.cs - it’s really tiny) that can read any noise data you like and apply it. The Multi-Channel-Perlin is just an example of what you can do.
Thanks to both, I modified Handheld_normal_mild preset for the idle and works pretty well. But the movements I was trying to do are a quite symmetrical, like a sine.
I will write some code for this states on CinemachineBasicMultiChannelPerlin.cs but this should be resolved on Cinemachine. I made these questions because this is one of the problems I found on Cinemachine. For these cases we need more settings. Perlin Noise is an option for an irregular terrain like a mountain, but if you are walking over a plane terrain, I need another kind of settings
Lowering the intensity does not change the way it is done. Also when the character runs, the camera movement is violent and quite symmetric, ergo, we need intensity. (perlin noise is not symmetric at all)
Yes I understand what you need. It’s a question of adding a non-random low-frequency signal to the noise, to simulate footsteps. It’s really quite easy to do yourself (even though you suggest that Cinemachine should provide it out-of-the-box). You can start by making a custom noise component. Copy CinemachineBasicMultiChannelPerlin.cs. Rename the copy to CustomNoise.cs (or something like that), and just add another channel to it that can hold your signal. You will find that the new component will magically appear in the vcam’s inspector, under the “Noise” section.
The point of this was to mark something that may be useful for cinemachine users. Obviously I do not pretend that cinemachine covers all the gaps in the development of any game because that is impossible, but this seemed useful, at least on fps.
Ok, now we have a virtual camera following the player, smooth and with the simulation of footsteps.
I have another question and, as the others, the solution could come from one thousand different forms. how could I solve this? Take a look to the minute 1:54
I wanna do something similar on the FPS. For example, I have a wall, on the top of the wall there is a message I want the player read when he is walking distracted over there. The camera must look at this point smoothly. I could make a transform.LookAt but I wondering if cinemachine could do that on other way. Any idea?
I would do it this way: Set up a second vcam, targeted at the wall message. When it is time to smoothly look at that target, enable (or increase the priority of) that vcam, and CM will smoothly blend from the normal vcam, and back again when you disable it.
Do you think is it a good idea to use Timeline and CM together in this kind of situations? maybe I have to move and rotate the player to look at the interest point, because in our case the player can look his own body… or maybe I’m making it too complicated and with only the camera move I’ve got the effect I want.