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:
using UnityEngine;
public class PlayerScript : MonoBehaviour
{
float xInput;
public float dodgeSpeed;
public float maxX;
public float speed;
public SpawnManager spawnManager;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (GameManager.instance.isGameRunning())
{
xInput = Input.GetAxis("Horizontal");
transform.Translate(xInput * dodgeSpeed * Time.deltaTime, 0, speed * Time.deltaTime * GameManager.instance.speedFactor);
float limitedX = Mathf.Clamp(transform.position.x, -maxX, maxX);
transform.position = new Vector3(limitedX, transform.position.y, transform.position.z);
}
}
private void OnTriggerEnter(Collider other)
{
spawnManager.SpwanTriggerEntered();
}
}