Car going really fast when followed

Hello, I ran to an issue where my car goes really fast and gets flown across the screen when hitting a collider, but only when the main camera is following it. If the camera isn’t following the car, then everything is fine. Not sure what I did wrong, I have a screen recording of the car going really fast but don’t know how to upload a video on this forum.
Thank you.


Hi Rayhan,

Welcome to our community! :slight_smile:

Please note, it’s better to copy/paste your code and apply the code fencing characters, rather than using screenshots. Screenshots are ideal for displaying specific details from within a game engine editor or even error messages, but for code, they tend to be less readable, especially on mobile devices which can require extensive zooming and scrolling.

You also prevent those that may offer to help you the ability to copy/paste part of your code back to you with suggestions and/or corrections, meaning that they would need to type a potentially lengthy response. You will often find that people are more likely to respond to your questions if you make it as easy as possible for them to do so.

Regarding your problem, check if the camera has got a collider attached. If the issue happens only if the camera follows the car, it might be that the camera has got a collider which pushes the car around.

Hope this helps. :slight_smile:


See also:

Hi Nina!

Thanks for your response, here is the code I used:

//FollowCamera.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FollowCamera : MonoBehaviour
{
    [SerializeField] GameObject thingToFollow;
    // Update is called once per frame
    void LateUpdate()
    {
        transform.position = thingToFollow.transform.position + new Vector3 (0,0,-10);
    }
}
//Driver.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class driver : MonoBehaviour
{
    [SerializeField] float steerSpeed = 20f;
    [SerializeField] float moveSpeed = 10f;
    // Start is called before the first frame update
    void Start()
    {
        // transform.Rotate(0, 0, 45); 
    }

    // Update is called once per frame
    void Update()
    {
        float steerAmount = Input.GetAxis("Horizontal") * steerSpeed * Time.deltaTime;
        float moveAmmount = Input.GetAxis("Vertical") * moveSpeed * Time.deltaTime;
        transform.Rotate(0, 0, -steerAmount);
        transform.Translate(0, moveAmmount, 0);
    }
}

Unfortunately, there is no collider in the camera. The only component that the camera has is the FollowCamera script.

Your screenshots look fine. So does your code. Which version of Unity do you use?

The car has got a Rigidbody2D component attached, hasn’t it? If so, try to increase the “drag” value. Depending on the speed of the car, it might be that the force the collision applies is fairly high.

Last but not least, build your game and test the build because the Game Window is just a laggy preview. It might be that your game is perfectly fine.

  1. Go to File > Build Settings.
  2. Add your scene to the Scenes list.
  3. Select “WebGL” in the Platform list.
  4. Click “Apply”.
  5. Click “Build and Run”.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms