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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

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.