To find the relative coordinates of the listener from the point of the sound source, you can use the following steps:
Calculate the distance between the listener's position and the sound source's position using the getDistanceBetweenPoints2D function.
Calculate the angle between the listener's position and the sound source's position by getting the angle between the two points using math.atan2(y2-y1, x2-x1)
Rotate the angle by the sound source's rotation (sound.rotZ) using math.rad(sound.rotZ)
Use this angle and the distance to calculate the relative x, y, and z coordinates of the listener from the sound source using math.cos(angle)*distance for the x coordinate and math.sin(angle)*distance for the y coordinate.
Use the resulting x, y, and z coordinates to position the listener on the sound source's vector.
here is an example of how the relative coordinates of the listener can be calculated using the steps I outlined above
local listener = {x = localPlayer.matrix:getPosition().x, y = localPlayer.matrix:getPosition().y, rotZ = localPlayer.matrix:getRotation().z}
local sound = {x = -1788.82507, y = -2689.26538, z = 4.26150, rotZ = 180 + 90}
local distance = getDistanceBetweenPoints2D ( sound.x, sound.y, listener.x, listener.y )
local angle = math.atan2(listener.y - sound.y, listener.x - sound.x) + math.rad(sound.rotZ)
local listenerRelativeX = math.cos(angle) * distance
local listenerRelativeY = math.sin(angle) * distance
local listenerRelativePos = {x = sound.x + listenerRelativeX, y = sound.y + listenerRelativeY, z = listener.z}
This code calculates the relative position of the listener from the sound source using the distance and angle between the listener and sound source, and the rotation of the sound source. The resulting position is stored in the listenerRelativePos variable, which contains the x, y, and z coordinates of the listener relative to the sound source.
Note that this code is missing the calculation of the z coordinate, you need to add the calculation of the z coordinate based on the requirement of your game or application.