Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Problem / bug with Velocity and Unity 5.3?

Discussion in 'Physics' started by Nicolas-Liatti, Apr 25, 2016.

  1. Nicolas-Liatti

    Nicolas-Liatti

    Joined:
    Jun 19, 2013
    Posts:
    89
    Hi,

    I have a very weird behavior with Unity 5.3.4: the velocity does not seem to follow the physics laws...

    I am trying to simulate a trajectory for an object, but the object never reach the exact destination.

    First one: we launch the object by setting the velocity:

    Code (CSharp):
    1.  Vector3 shootDir = Quaternion.Euler (-50.59f, 0, 0) * Vector3.forward;
    2. force = shootDir * 10;
    3. GoToLaunch.transform.GetComponent<Rigidbody> ().velocity = force;
    I made a little test by assigning those 2 scripts to 2 different game objects:


    2nd object: we compute the trajectory following the physics rules:

    Code (CSharp):
    1. float timer;
    2. float force;
    3.  
    4. void Start(){
    5.    timer = Time.time;
    6.   Vector3 shootDir = Quaternion.Euler (-50.59f, 0, 0) * Vector3.forward;
    7. force = shootDir * 10;
    8. }
    9.  
    10. void Update(){
    11.      float t = Time.time - timer; //timer = Time.time, in Start()
    12.      transform.position = force * t + Physics.gravity * t * t * 0.5f;
    13. }
    14.  
    The 2 spheres should follow the same path, but it's not the case.



    Is this a bug? or is there something I am missing?
     
unityunity