Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

CamFollow for car game (Help)

Discussion in 'Scripting' started by DiddyHopU, Jan 19, 2020.

  1. DiddyHopU

    DiddyHopU

    Joined:
    Nov 6, 2015
    Posts:
    3
    Hi everyone.

    I'm currently working on a racing game and I want a camera better than the "Smooth follow" (doesn't work well for my game even in the testing phase).

    I know exactly what i'm after. I would like it to operate like a boom pole with the car being the center and the camera facing forwards with the car. (like this https://i.imgur.com/ArpWsGs.mp4)

    I'd also like to have some smoothing applied at two different float values, one for the follow and the other for the rotation.

    I'm not really sure where to begin with this, other than "find the cars position and rotation" which i've done with this:

    Code (CSharp):
    1. private GameObject playerCar;
    2. private float playerCarDirection;
    3.  
    4. void Start()
    5. {
    6. playerCar = GameObject.FindGameObjectWithTag("Player");
    7. }
    8.  
    9. void Update()
    10. {
    11. playerCarDirection = playerCar.transform.rotation.eulerAngles.y;
    12. }
    Any help with getting something smooth and functional working would be greatly appreciated!
     
  2. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,748
    Little confused, you say Smooth Follow doesnt work for your game but then you describe what you do want and it sounds exactly like smooth follow?
     
  3. SolarFalcon

    SolarFalcon

    Joined:
    Nov 28, 2015
    Posts:
    170
    Try using Cinemachine. It has some cameras that might work better for you. Also, the virtual camera blending functionality is awesome.

    You can find it in the Package Manager.
     
    Kurt-Dekker likes this.
  4. DiddyHopU

    DiddyHopU

    Joined:
    Nov 6, 2015
    Posts:
    3
    Cheers for the responses, as for why i didn't want to use smooth follow it's really because I wanted to learn how to do it myself. I find it hard to penetrate pre-written code and find i learn more from doing and then that understanding helps me modify things more.

    I've gotten this sorted now though, so thanks!