Need help determining if a waypoint will be to the left or right of entity

Hey guys! Simple request - Trying to get a plane voice-based navigation assistant to follow a waypoint / coordinate system. The problem is that I don’t really know how to get the entity to determine the proper left, right heading (without hardcoding the turn every time, that is…). I want to be able to say:

Plane is midair. Waypoint is (location). Turn [left / right] to heading (heading of waypoint).

AS dope as that sounds, I can’t seem to find any natives that can support this. I know we have get entity headings, get entity coords, etc, however, I can’t seem to find like a:
gettargetentityheading (which would give the correct heading based on where I’m situated) or a

getentitycoordsrelativetoentity (which would give the distance relative to myself)

Any thots?

One solution could be to get a coord from the left of the plane, and one from the right with GetOffsetFromEntityInWorldCoords - Natives @ Cfx.re Docs and you could check which one is closer to the waypoint to know which direction to go.

Somebody here could have a better idea, but this one should work.

1 Like

You fucking madman! That may just work! My only question is, how would I compare those two coords (or dots on both sides of the plane) with the target waypoint?

Simple lua, existing native, or “go figure it out scrub”?

Your choice! :wink:

Make sure to use vector, and you can do something like :

local mywaypoint = vector3(?, ?, ?)
local leftPlane = vector3(?, ?, ?)
local rightPlane = vector3(?, ?, ?)

if #(mywaypoint - leftPlane) < #(mywaypoint - rightPlane) then
    -- left
else
    -- right
end
1 Like

WHOA! You can perform arithmetic on vector3’s like that?!?!?!?!?!?!?!?

You just blue (bleu / blew) my mind!!!

Thanks for the insight man! :smiley:

You’re welcome :smiley:

(Don’t forget to mark the post as resolved if it is :slight_smile: )

I will mark your answer as resolved definitely, but quick question (so that I know for next time).

I really didn’t know you can subtract two coordinates to find the lower distance between two such as your example.

Just a few post-mortem questions:

  1. How does it determine the lower value in this example? (does it pick the lowest value of them both?)
  2. How did you know that you can perform such arithmetic on coordinates? Is this a general video game thing, programmers intuition? Experience?
  3. Is there a course on fivem / lua scripting that you could share that covers this and similar? Or anything like this that helps me get into the programmer’s mindset?

Im super impressed by your help and just wanted to be able to aspire to get to your level one day!! :smiley:

Thanks again for your help thusfar! :smiley:

I don’t really know how it works internally, but it should not need to know the lowest value, look at how you can get the distance between two vectors : The Distance Between Two Vectors - Mathonline
image


Thanks to the forum and spending some time on the discord of cfx :


You can find some informations here : vector3 - Cfx.re Docs (and more here : List of functions in Lua - Cfx.re Docs )

This topic could interest you : [Best practice] Improve your resource performance

Best thing you can do to learn is to spend some time on the forum and discord to look at what people can answer and suggest :slight_smile:

1 Like

You’re a lovely human being! Thanks for your guidance, help, and resources! I’ll make sure to learn so that I won’t have to ask anymore!

1 Like

Good luck on your journey here :smiley:

1 Like

Currently scraping the forums to answer questions that I find simple and came across this post.
Actual top tier responses to the OPs questions, mate. Glad we have you in this community! +rep

2 Likes

Thank you for this message @DrAceMisanthrope, it warms my heart. :heart:

1 Like