Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Unity camera follow player with fixed distance

Discussion in 'General Discussion' started by alexk28052009, Jul 26, 2023.

  1. alexk28052009

    alexk28052009

    Joined:
    Jul 26, 2023
    Posts:
    3
    I am trying to make this game where the distance between your character and the camera is 0.266, the camera is in front of the player and when you look down you see your own body. Everything works well but when you start rotating the character does rotate but since the camera is 0.266m in front of it and you rotate 180° you see your own eyes.

    Image of you just looking down:
    upload_2023-7-26_19-34-12.png

    Image of you looking in the other direction:
    upload_2023-7-26_19-34-34.png

    How do I fix this issue I brainstormed of ideas how I can fix this but just can't implement them. I tried making the character basically orbit the camera while rotating and the same with the camera. Can someone please try to help me?

    Thanks ahead
     
  2. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    9,724
    Put the eyes and other general head parts on a different layer and exclude that from the layers the camera renders.
     
  3. alexk28052009

    alexk28052009

    Joined:
    Jul 26, 2023
    Posts:
    3
    That is a really good suggestion but it wouldn't work because I want the player to see his legs when you look down and when you turn around the legs would look like this: upload_2023-7-26_19-46-6.png
    So the legs would be visible from behind + I think it would even mess up the games hitbox triggers
    But anyways thank you, do you have possibly a better solution?
     
  4. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    9,724
    Shorten the camera's near plane distance and move it forward slightly. You don't want to have it at the centre of the head anyway, you want it to be roughly at the eye position.

    Nothing about this is going to ever be one size fits all, full body awareness is something that tends to have to be tailored for each individual game
     
  5. alexk28052009

    alexk28052009

    Joined:
    Jul 26, 2023
    Posts:
    3
    But the head is not obstructing the view normally just when you look back I am just trying to figure out how to possibly code a script where the character would always be .266m behind the main camera but I programmed it that if you rotate the character rotates too and when you rotate with the camera being .266m in front of the character 180° you see your eyes and when you look down you see the legs so how would I make it that the body is always teleporting 0.266m behind you even if you rotate
     
  6. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    9,724
    You make the camera the child of a gameobject, offset the camera there, and rotate the gameobject instead.
     
  7. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,317
    One of the following ideas:

    1. Don't let the player rotate 180.
    2. When rotating over 90 start turning the body.
    3. Remove head, replace neck with a stump. Do not let the player look at the stump.

    Also you need to move znear/near clipping plane closer in camera settings. It shouldn't be clipping shoulders, set it to something like 0.01 or 0.001.