void Update() { if (i++ % SpawnRate != 0) { return; } GameObject spawnedTorpedo = Instantiate(torpedo, transform.position, transform.rotation, GameManager.WorldTransform); InterceptDriveAccel drive = spawnedTorpedo.GetComponent <InterceptDriveAccel>(); drive.targetDrive = target; drive.accel = torpedoAccel; drive.rb.velocity = parent.rb.velocity + initalV.normalized * launchSpeed; drive.waitTime = waitTime; }
public static float FindRealSolutionSmallestT(InterceptDriveAccel drive, Drive targetDrive) { if (drive == null || targetDrive == null) { return(float.PositiveInfinity); } Vector3 rv = targetDrive.rb.velocity - drive.rb.velocity; Vector3 rp = targetDrive.rb.position - drive.rb.position; double[] coefficients = { 4d * rp.sqrMagnitude, 8d * Vector3.Dot(rv, rp), 4d * (Vector3.Dot(targetDrive.accelVec,rp) + rv.sqrMagnitude), 4d * Vector3.Dot(targetDrive.accelVec, rv), targetDrive.accelVec.sqrMagnitude - drive.accel * drive.accel }; return(InterceptSolver.FindRealSolutionSmallestT(coefficients)); }