public void AimAtPosition(Vector3 position) { reticleTransform.position = position + Vector3.up * 5; float distance = Vector3.Distance(originTransform.position, position); float initialHeight = originTransform.position.y - groundHeight; float targetHeight = groundHeight + position.y; float angle = Trajectory.AngleOfReach(distance, velocity, initialHeight, targetHeight, -Physics.gravity.y); if (float.IsNaN(angle)) { return; } Vector3 pos = cannonTransform.eulerAngles; SetVector3AxisValue(ref pos, angle * Mathf.Rad2Deg - pitchOffset, pitchAxis); Vector3 diff = position - cannonTransform.position; angle = Mathf.Atan2(diff.x, diff.z); SetVector3AxisValue(ref pos, angle * Mathf.Rad2Deg - yawOffset, yawAxis); cannonTransform.eulerAngles = pos; DrawTrajectory(originTransform.position, position, distance); // and once again by cannon angle //CalculatePath(); }