Search Unity

Game is glitching out

Discussion in 'Scripting' started by Usermanes232, Nov 9, 2017.

  1. Usermanes232

    Usermanes232

    Joined:
    Nov 9, 2017
    Posts:
    1
    So I finally managed to input controls for my ball but it's super glitchy and flies around, It has rigidbody in it and Here's the code BTW:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class NewBehaviourScript : MonoBehaviour {
    void Start () {


    }
    float speed = 0.13f;

    void Update () {
    var X = Input.GetAxis ("Horizontal") * speed;

    transform.Translate (X, 0, 0);

    }
    }
     
  2. UziMonkey

    UziMonkey

    Joined:
    Nov 7, 2012
    Posts:
    206
    You'll also want to multiply the speed by Time.deltaTime and increase the speed by quite a lot. You'll want your speed in units per second, where right now you have them in units per frame.
     
  3. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    You'll also want to use physics forces to move your object, otherwise you're basically teleporting it and the physics engine is going to throw a fit any time it interacts with anything.