Xwad Posted October 15, 2019 Share Posted October 15, 2019 (edited) 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 Edited October 15, 2019 by Xwad Link to comment
Overkillz Posted October 15, 2019 Share Posted October 15, 2019 Probably getTickCount() Will solve your problem. Just when the "Bomb" reach the point where you want it, get the timer using local startTick = getTickCount() --When the bomb reach the point just get the time local timeVariable = getTickCount() - startTick Regards. Link to comment
Xwad Posted October 16, 2019 Author Share Posted October 16, 2019 (edited) But im trying to add a croshair to the ground position where the bomb will fall to. I am using the free fall formula: local time = vz - math.sqrt( vz*vz + height * 19.6 ) / -9.8 VZ : initial speed of the element when its released from the plane height : height of the plane (in meters) and the 19.6 (9.8x2) is the gravitational acceleration. When i get the time then i can calculate the y distance by multiplicating the time with the planes speed (m/s). Edited October 16, 2019 by Xwad Link to comment
Overkillz Posted October 16, 2019 Share Posted October 16, 2019 If you are trying to add a crosshair in the groun. You can use dxDrawMaterialLine3D() Read carefully the arguments to draw it correctly. Link to comment
Xwad Posted October 16, 2019 Author Share Posted October 16, 2019 No, that's not exactly what i need. I have problems with maths. Look, i uploaded the script to mediafire! https://www.mediafire.com/file/b3xd1n4ws979zgu/crosshair.rar/file I did not express myself clearly enough so i think the easiest way is if i give you the script so you can test it. Link to comment
Xwad Posted October 16, 2019 Author Share Posted October 16, 2019 I fixed some bugs but its still not perfect. idk why. https://www.mediafire.com/file/frrcxykix48mg29/crosshair.rar/file Link to comment
Overkillz Posted October 16, 2019 Share Posted October 16, 2019 Im not sure about this, but try to use set as gravity 0.8 Btw, Im not understanding what do you really want. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now