// Update is called once per frame void Update() { accumulator += Time.deltaTime; //update 60 times per second (this limits the physic time step) //to make the movement look smoother we can always use linear interpolation while (accumulator > TIME_STEP) { float deltaTime = Time.time - lastTime; if (deltaTime <= 0.0f) { deltaTime = TIME_STEP; } lastTime = Time.time; Vector3 oldPos = transform.position; Solver(deltaTime); SphereCollider.RigidBody.Velocity = velocity; if (SphereCollider.Intersect(PlaneCollider)) { velocity = Vector3.zero; transform.position = oldPos; } accumulator -= TIME_STEP; } }
// Update is called once per frame void Update() { // If the next update is reached if (Time.time >= nextUpdateTime) { if (!SphereCollider.Intersect(PlaneCollider)) { transform.position = calculatePosition(nextUpdateTime); } nextUpdateTime += TIME_STEP; } }