How to Make CAMERA FOLLOW PLAYER

Does anyone know a script for making the camera attached to the player? I dont know why I cant just put the camera as a child of the player.

Im just trying to make a first person game, but for some reason i cant place the camera as a child of the player in order to follow player.

Please help me.

Can you explain what is stopping you from doing that?

1 Like

I don’t know why you can’t either.

I also don’t know any other way to do it.

But you didn’t explain to us why you can’t.

There are a lot of Unity FPS tutorials out there to check out with TONS of interesting stuff.

Otherwise, here is how to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

How to understand errors in general:

https://discussions.unity.com/t/824586/8

If you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: https://discussions.unity.com/t/481379

@PraetorBlue @Kurt-Dekker
I can’t put my camera as a child of my player. (Well, technically I can but nothing will happen.)
I suspect this is because I am using model assets that I brought onto Unity. I hate how Unity goes berserk every DAMN time I use an asset. There will almost definitely something go wrong if I use an asset.

Whenever I put the camera as a child of the player, it follows it around. BUT, and this is a big but, IT NEVER WORKS WITH ASSETS!

Perhaps you just need an extra level of parenting.

For instance, let’s say this is your asset hierarchy

MyProblematicAsset
   ItHasChildren
   AndOtherChildren
       WithChildren

Odds are if you stick the camera in there, maybe something goes wrong.

Instead, make a new prefab with the asset as part of it:

MyShinyNewRootObject
   CameraOffsetter
       TheMainFPSCamera
   MyProblematicAsset
       ItHasChildren
       AndOtherChildren
           WithChildren

If there was some script on MyProblematicAsset, move it to MyShinyNewRootObject and reconnect stuff if necessary, such as animator and/or other transforms.

Then use CameraOffsetter to align the camera with where you want.

This sorta thing can solve so many rotational and offset issues everywhere in gamedev and Unity.

I found a nice script that follows the player nicely

If you want a script, it is super simple. You’d just have a reference to a target transform (the player character, probably where they head is supposed to be), and in LateUpdate you just set the transform.position and transform.rotation the same as the target transform.

But you should still be able to do it by childing.

Just in here to brag?

LOL Joe not at all, I battled with it a while and found this script that really worked well for me. But I do suppose that takes away a learning experience for the OP. Depends on him.

I think you need to spend some time working out what is going on. Parenting the camera to the player should work ok. If it’s not, try and understand why.

1 Like