bool DetectCollision(VectorLine self, VectorLine other) { float[] constants = VectorLine.GetIntersectConstants(self, other); if (constants[0] < 0 || constants[1] < 0) //both have to be positive for eminent collision { return false; } float collision_threshold = 0.5f; //give and take 0.5s Vector3 collision_pt = VectorLine.GetIntersectionPoint(self, other); //calculate time it takes for self float self_disp = Mathf.Pow((collision_pt - self.GetPoint()).sqrMagnitude, 0.5f); float self_time = self_disp / self.GetSpeed(); //calculate time it takes for other float other_disp = Mathf.Pow((collision_pt - other.GetPoint()).sqrMagnitude, 0.5f); float other_time = other_disp / other.GetSpeed(); float time_diff = Mathf.Abs(self_time - other_time); Debug.Log("self time: " + self_time + "other time: " + other_time); Debug.Log("time diff: " + time_diff); return time_diff <= collision_threshold; //collision detected if they collide within 0.5s of each other }