Search Unity

Unity car movement

Discussion in 'Getting Started' started by Yegor42069, Dec 5, 2022.

  1. Yegor42069

    Yegor42069

    Joined:
    Dec 5, 2022
    Posts:
    26
    I just started unity and I'm doing the tutorial that is provided within the app and I was following this one tutorial about player movement I copied everything exactly like he said in the video . I was trying to control a car and the code that i had written was supposed to make it move forward but when I ran the game it didn't work

    here is the code
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayerController : MonoBehaviour
    6. {
    7.     // Start is called before the first frame update
    8.     void Start()
    9.     {
    10.      
    11.     }
    12.  
    13.     // Update is called once per frame
    14.     void Update()
    15.     {
    16.        // Basic code for forward moving vechicle
    17.        transform.Translate(0, 0, 1);
    18.     }
    19. }
    20.  
     
    Last edited: Dec 5, 2022
  2. Yegor42069

    Yegor42069

    Joined:
    Dec 5, 2022
    Posts:
    26
  3. RichAllen2023

    RichAllen2023

    Joined:
    Jul 19, 2016
    Posts:
    1,026
  4. Yegor42069

    Yegor42069

    Joined:
    Dec 5, 2022
    Posts:
    26
    its not working
     
  5. Yegor42069

    Yegor42069

    Joined:
    Dec 5, 2022
    Posts:
    26
    The car is supposed to be moving forward but it aint
     
  6. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,433
    Did you add this "PlayerController" component to your car?

    I think your velocity is pretty big. If the car just seems to disappear, it's because it drove away at 60 meters per second or more. Try
    1f * Time.deltaTime
    instead of 1 in your transform line, and it will roll at a more likely scale.
     
  7. Yegor42069

    Yegor42069

    Joined:
    Dec 5, 2022
    Posts:
    26
    The car doesnt dissapear it just doesnt move
     
  8. AngryProgrammer

    AngryProgrammer

    Joined:
    Jun 4, 2019
    Posts:
    490
    Your script is correct, you probably didn't add it to the game object.