My car is going too fast

I wrote everything the same, but my car flies off the screen and goes very fast. Can anyone help me see what I did wrong?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Driver : MonoBehaviour
{
[SerializeField] float steerSpeed = 1f;
[SerializeField] float moveSpeed = 0.01f;
void Start()
{

}

void Update()
{
    float steerAmount = Input.GetAxis("Horizontal");
    transform.Rotate(0, 0, steerAmount);
    transform.Translate(0,moveSpeed,0);
}
}

Hi Novice164,

Welcome back to our community! :slight_smile:

If you have a fast computer, it might be that the car is super fast because the Update method gets executed each frame. Each frame, your code moves the car by 0.01f World Units (WU). If you have a framerate of, for example, 200, your car would move 0.01 x 200 WU per second.

In the next video (“Using Time.deltaTime()”), we make the code framerate-independent. Please keep watching. :slight_smile:


See also:

1 Like

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

Privacy & Terms