- Home /
Projectile Physics - Why do i get a different result when using Time.sinceLevelLoad over Time.delatime in Unity?
I'm playing around with projectile physics on objects in Unity. In this case I'm just using a sphere object and calculating it's vector and the path it should take based on gravity (leaving other forces like friction out for the moment).
The formula I'm using is the following: s = ut + ½at²
and the code solution is simple enough as follows:
using UnityEngine;
using System.Collections;
public class TestProjectileForce : MonoBehaviour {
// Create vector components to calculate force & position
private float force = 1.8f;
private float g = 9.8f;
private float angle = 30f;
private float fx;
private float fy;
// projectile calculate
private float dis_x;
private float dis_y;
// Use this for initialization
void Start () {
// calculate x & y vector
fx = Mathf.Round (force * Mathf.Cos(Mathf.Deg2Rad * angle));
fy = Mathf.Round (force * Mathf.Sin(Mathf.Deg2Rad * angle));
}
// Update is called once per frame
void Update () {
// s = ut + 1/2at2
dis_x = (float)(fx * Time.timeSinceLevelLoad);
dis_y = (float)(fy + Time.smoothDeltaTime + (0.5) * (-g) * Time.timeSinceLevelLoad * Time.timeSinceLevelLoad);
Debug.Log (dis_x+", "+dis_y);
transform.Translate (new Vector2(dis_x, dis_y));
}
}
I noticed however, that the expected result i should get varies greatly depending on if i use Time.sinceLevelLoad
over Time.deltaTime
. Can anyone explain to me why this is? When using Time.sinceLevelLoad
i get the expected result of the ball arcing and dropping given the force of gravity acting upon it, however with Time.deltatime
the balls will just shoot off and not arc as expected.
Answer by meat5000 · Mar 16, 2015 at 12:16 AM
deltaTime is time between one frame to the next.
sinceLevelLoad is self explanatory.