Question Main Camera and weapon holder for fps games

I thought it’s usually not good to make things a child of the main camera because if we have an effect such as a screen shake, then it would affect the children too? For our weapons, wouldn’t it be better to not make them a child of the main camera?

I tried doing this on my own and then using a script to make the weapon follow where the camera is pointing, however whenever I do this, my weapon always stutters. Is there a proper way to do this?

Current Project Hierarchy (Item Holder is a child of the MainCamera Game Object)
image

Ideal Project Hierarchy (Item Holder is a child of the Player Game Object)
image

Hi Kp4ws,

First a little reminder: What we see in the game window is what the camera renders. The camera does not shake the screen. Just like we don’t shake the world when shaking our head.

For this reason, I think your “Ideal Project Hierarchy” is either the solution of your problem or at least this approach is part of the solution.

What happens if you remove your script and use your “Ideal Project” structure? If you manually move the “Player” game object relative to the camera, you should get the same result as before. Just do not move any of the children of the “FPS_Player” via code. Then the camera (a child of “FPS_Player”) should be shaking itself without affecting the weapons.

Hi Nina,

Bad wording on my part but yes I meant camera shake, not screen shake. If I did add a camera shake effect (or something similar) would this affect the child objects of the camera ?

When I make my weapons a child of the player (Ideal Project Hierarchy), they only rotate horizontally with the player but since the player body doesn’t rotate vertically, the weapons do not rotate up/down when I look up/down with the camera. In turn if I add a script to make them rotate with the camera, this is when I get stuttering (mostly stuttering just when looking up or down, horizontal seems to still be fine).

For the time being, I’ll probably leave the weapons as a child of the main camera. More or less curious on alternative approaches.

Yes, it would.

In turn if I add a script to make them rotate with the camera, this is when I get stuttering (mostly stuttering just when looking up or down, horizontal seems to still be fine).

The main problem is that your code depends on code you do not know (= the cinemachine code and the Camera code, which are not open-source). For this reason, debugging is difficult, and you can only guess and find a solution via trial and error. In your code, test a method such as LateUpdate instead of Update. Maybe that’ll help.

Also, without knowing anything about what you did, all I can do is guessing around. Maybe this will solve the problem.

Please feel free to ask our helpful community of students for further ideas over on our Discord chat server.

Good luck! :slight_smile:

Privacy & Terms