Need suggestion on development levle

this is the originol code

’ if (not gps_or_ekf_bad) then
local home = ahrs:get_home()
local curr_loc = ahrs:get_location()
if home and curr_loc then
home_dist = curr_loc:get_distance(home)
home_yaw = math.deg(curr_loc:get_bearing(home))
elseif (update_user) then
– warn user of unexpected failure
gcs:send_text(0, “DR: could not get home or vehicle location”)
end
end’

i have modified the code a bit like below

'if (not gps_or_ekf_bad) then
local home = ahrs:get_home()
local curr_loc = ahrs:get_location()
if home and curr_loc then
home_dist = curr_loc:get_distance(home)
current_pitch = ahrs:get_pitch() – Update: Get the current pitch from ahrs

-- Rest of your code using current_pitch goes here

elseif (update_user) then
– warn user of unexpected failure
gcs:send_text(0, “DR: could not get home or vehicle location”)
end
end’

My Goal is to reach the next waypoint (pitch, yaw) to the current heading, to move the vechle forward in guided_no_Gps mode, i get a bit success but not perfect (tested in SITL), the error are look like this

can anyone help me in this project?