Hi, I’m new creating FiveM topics, but I am lost with one of my resources, I will explain my problem:
I have a point (a) which is a vector3, and a target (b) which is a vector3 too. I want to calculate the path of a parabola to create 3d lines and display them IN-GAME. I managed seeing some youtube videos how to create it, when I change the target value is all correct, it seems to work as I want. But when I change the point (a), all starts to glitch. The point (a) seems to be always (0.0, 0.0, 0.0), and it changes the point (b), when I am only changing the point (a). I will leave some code that I have write and see if someone can help me, I am frustrated hahah:
local gravity = -9.8 -- Gravity
local h = 100.0 -- Max height later changed
local numPuntos = 0 -- Point number later changed
function CalcularDesplazamiento(velInicial, tiempoActual)
local desplazamientoX = velInicial.x * tiempoActual
local desplazamientoY = velInicial.z * tiempoActual + gravity * tiempoActual * tiempoActual / 2
local desplazamientoZ = velInicial.y * tiempoActual
return vector3(desplazamientoX, desplazamientoZ, desplazamientoY)
end
function CalcularVelocidadInicial(desde, hacia)
local desplazamientoP = hacia - desde
local velocidadY, velocidadX, velocidadZ
velocidadY = math.sqrt(-2 * gravity * h)
velocidadX = desplazamientoP.x / ((-velocidadY / gravity) + math.sqrt(2 * (desplazamientoP.z - h) / gravity))
velocidadZ = desplazamientoP.y / ((-velocidadY / gravity) + math.sqrt(2 * (desplazamientoP.z - h) / gravity))
return vector3(velocidadX, velocidadZ, velocidadY)
end
function CalcularTiempoTotal(velInicialY, hacia)
return -velInicialY / gravity + math.sqrt(2 * (hacia - h) / gravity)
end
Citizen.CreateThread(function()
while true do
local desde, hacia = vector3(0.0, 0.0, 0.0), GetEntityCoords(PlayerPedId()) -- Starting coords, and target coords
h = hacia[3] + 600.0
local velInicial = CalcularVelocidadInicial(desde, hacia) -- Initial velocity
local tiempoTotal = tonumber(CalcularTiempoTotal(velInicial.z, hacia)[3]) -- Total time
local tiempoActual = 1.0 -- Actual time
numPuntos = #(hacia - desde) * 2 -- Number of points that I will draw (dinamically)
local paso = tiempoTotal / numPuntos -- Steps
hacia = CalcularDesplazamiento(velInicial, tiempoActual) -- Calculate desplazament
while tiempoActual <= tiempoTotal do
desde = hacia
hacia = CalcularDesplazamiento(velInicial, tiempoActual)
DrawLine(desde, hacia, 0, 250, 0, 255) -- Drawing the lines needed
tiempoActual = tiempoActual + paso
end
print(desde, hacia) -- Some random prints :)
Citizen.Wait(0)
end
end)
This leaves me with: