Hi. I started creating a new plane bombing script. I created this code that calculates the x,y,z position, where the element (bomb) will fall to.
There is only one problem. It's bugging (the positions are not always correct) and i can't fix it. Any idea? Thx.
local face = dxCreateTexture( "crosshair.png" )
function output_bombs()
local veh = getPedOccupiedVehicle(localPlayer)
local speed = getElementSpeed(veh, 0)
local px,py,pz = getElementPosition(veh)
local rx,ry,rz = getElementRotation(veh)
local vx,vy,vz = getElementVelocity(veh)
local ground = getGroundPosition(px,py,pz)
local height = pz - ground
local vz = vz * -50
if vz < 0 then
vz = vz * -1
end
local time = vz - math.sqrt( vz*vz + height * 19.6 ) / -9.8 -- THAT'S IT
if time < 0 then
time = time * -1
end
local distanceY = speed * time
local npx = px + distanceY
local npy = py + distanceY
local x,y,z = getPositionFromElementOffset(veh,0,distanceY,0)
local ground = getGroundPosition(npx,npy,pz)
dxDrawImage3D( x,y-10,ground+1, 0,20, face, tocolor( 255,255,255, 255 ), 0, false, x,y,z )
dxDrawText ( "height: "..height, 400,100, 0,0, tocolor ( 240,240,240, 255 ), 1.5 )
dxDrawText ( "speed: "..speed, 400,50, 0,0, tocolor ( 240,240,240, 255 ), 1.5 )
dxDrawText ( "fall time: "..time, 400,150, 0,0, tocolor ( 240,240,240, 255 ), 1.5 )
dxDrawText ( "initial speed: "..vz, 400,250, 0,0, tocolor ( 240,240,240, 255 ), 1.5 )
end