Search Unity

Make GameObject fly

Discussion in 'Documentation' started by BigBrotherParties, Feb 24, 2017.

  1. BigBrotherParties

    BigBrotherParties

    Joined:
    Feb 22, 2017
    Posts:
    13
    I have this code:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class CubeTest : MonoBehaviour {
    6.     public string Hello;
    7.     float life = 100;
    8.     public float speed = 1.5f; //vitesse cube
    9.     public Rigidbody cube;
    10.  
    11.     // Use this for initialization
    12.     void Start () {
    13.         Debug.Log (Hello + "You have" + life + "%");
    14.         cube = GetComponent<Rigidbody> ();
    15.             cube.mass = 2;
    16.             cube.drag = 0;
    17.             cube.isKinematic = false;
    18.         cube.AddForce (Vector3.up * 10);
    19.     }
    20.  
    21.    
    22.     // Update is called once per frame
    23.     void Update () {
    24.         transform.position += new Vector3 (0, 2, 0) *Time.deltaTime;
    25.     }
    26. }
    27.  
    With this, I just want make my GameObject(cube) fly in the air and it make this:
    https://gyazo.com/a4308faec561c6f8fa4818dade776ae4
    I found one solution is to take off the
    Code (CSharp):
    1. *Time.delta.time
    but it doing this:
    https://gyazo.com/2074ee9ccd8cf9604c2f20e70c6ffb5c
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Post this question in the Scripting forum. This is not Documentation-related.
     
  3. BigBrotherParties

    BigBrotherParties

    Joined:
    Feb 22, 2017
    Posts:
    13
    oK, but can you ansewer me, if you know ?