private Vector3 getVelocityForTarget(Vector3 position, Vector3 target, float initialAngle) { float gravity = GameSettings.gravity; // Selected angle in radians float angle = initialAngle * Mathf.Deg2Rad; // Positions of this object and the target on the same plane Vector3 planarTarget = new Vector3(target.x, 0, target.z); Vector3 planarPostion = new Vector3(position.x, 0, position.z); // Planar distance between objects float distance = Vector3.Distance(planarTarget, planarPostion); // Distance along the y axis between objects float yOffset = position.y - target.y; float speed = ProjectileUtils.LaunchSpeed(distance, yOffset, gravity, angle); Vector3 velocity = new Vector3(0, speed * Mathf.Sin(angle), speed * Mathf.Cos(angle)); float angleBetweenObjects = Vector3.SignedAngle(Vector3.forward, planarTarget - planarPostion, Vector3.up); timeOfFlight = ProjectileUtils.TimeOfFlight(speed, angle, yOffset, gravity); return(Quaternion.AngleAxis(angleBetweenObjects, Vector3.up) * velocity); }