// Update is called once per frame void Update() { d1 = plane.distance_to(transform.position) - Radius_Of_Sphere; velocity += acceleration * Time.deltaTime; transform.position += velocity * Time.deltaTime; float distance_from_center_to_plane = plane.distance_to(transform.position); d2 = distance_from_center_to_plane - Radius_Of_Sphere; if (d2 <= 0) { Bounce(); } }
// Update is called once per frame void Update() { float d1 = plane.distance_to(transform.position) - Radius_Of_Sphere; velocity += acceleration * Time.deltaTime; transform.position += velocity * Time.deltaTime; float distance_from_center_to_plane = plane.distance_to(transform.position); float d2 = distance_from_center_to_plane - Radius_Of_Sphere; if (d2 <= 0) { Vector3 parallel = parallel_component(velocity, plane.normal); Vector3 perp = perpendicular_component(velocity, plane.normal); float time_of_impact = Time.deltaTime * d1 / (d1 - d2); transform.position -= velocity * (Time.deltaTime - time_of_impact); velocity = perp - Coefficient_of_Restitution * parallel; transform.position += velocity * (Time.deltaTime - time_of_impact); } }