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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Motion from my car is lagging

Discussion in 'Getting Started' started by matthias1993, Jun 7, 2022.

  1. matthias1993

    matthias1993

    Joined:
    Apr 25, 2022
    Posts:
    1
    Hi everyone,

    I'm brand new to Unity. So this is probably quite a beginner's question.

    I want to drive a car on an endless road.
    And the movement of my car is quite laggy.

    Does anyone have any ideas as to what could be causing this?

    Here is the code of my car:
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class PlayerScript : MonoBehaviour
    4. {
    5.     float xInput;
    6.  
    7.     public float dodgeSpeed;
    8.     public float maxX;
    9.  
    10.     public float speed;
    11.  
    12.     public SpawnManager spawnManager;
    13.     // Start is called before the first frame update
    14.     void Start()
    15.     {
    16.        
    17.     }
    18.  
    19.     // Update is called once per frame
    20.     void Update()
    21.     {
    22.         if (GameManager.instance.isGameRunning())
    23.         {
    24.             xInput = Input.GetAxis("Horizontal");
    25.             transform.Translate(xInput * dodgeSpeed * Time.deltaTime, 0, speed * Time.deltaTime * GameManager.instance.speedFactor);
    26.             float limitedX = Mathf.Clamp(transform.position.x, -maxX, maxX);
    27.  
    28.             transform.position = new Vector3(limitedX, transform.position.y, transform.position.z);
    29.         }
    30.     }
    31.  
    32.  
    33.     private void OnTriggerEnter(Collider other)
    34.     {
    35.         spawnManager.SpwanTriggerEntered();  
    36.     }
    37. }
    38.  
     

    Attached Files:

  2. bekaoktabris

    bekaoktabris

    Joined:
    Jun 9, 2022
    Posts:
    2
    Здравствуйте а вы пробовали ее увеличить в компонентах?