Karuzo Posted August 26, 2014 Posted August 26, 2014 Hello Guys, I want to know how i can calculate the exact position of a car/car-part. I want this part of the car: I hope you can help me.
John Smith Posted August 26, 2014 Posted August 26, 2014 I think you could use https://wiki.multitheftauto.com/wiki/Ge ... ntPosition And then get spoiler position But not sure since i've never used that function If you find my post useful or if it helped you, please like my post Ingame name: ZoeN
Moderators IIYAMA Posted August 27, 2014 Moderators Posted August 27, 2014 function getPositionFromElementOffset(element,offX,offY,offZ) local m = getElementMatrix ( element ) -- Get the matrix local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1] -- Apply transform local y = offX * m[1][2] + offY * m[2][2] + offZ * m[3][2] + m[4][2] local z = offX * m[1][3] + offY * m[2][3] + offZ * m[3][3] + m[4][3] return x, y, z -- Return the transformed point end addCommandHandler("getThisPart", function () local vehicle = getPedOccupiedVehicle ( localPlayer ) if vehicle then local x,y,z = getPositionFromElementOffset(vehicle,0,0,10)-- offset x,y,z end end) https://wiki.multitheftauto.com/wiki/GetElementMatrix Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Karuzo Posted August 27, 2014 Author Posted August 27, 2014 Ah, I didn't see that function Thanks IIYAMA.
Moderators IIYAMA Posted August 27, 2014 Moderators Posted August 27, 2014 np. Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Karuzo Posted August 27, 2014 Author Posted August 27, 2014 Hey, I just tried that function and i have a problem now. If i create the object(which i want to attach to the car) without attaching it to the car, it is on the position where i want it. But if i create it and attach it right after that, the position is different and i can't even see the object. This is my code: addCommandHandler("t", function () local vehicle = getPedOccupiedVehicle ( localPlayer ) if vehicle then local x,y,z = getPositionFromElementOffset(vehicle,0,3,0) local rx,ry,rz = getElementRotation(vehicle) element = createObject(1060,x,y,z,rx,ry,rz,false) outputDebugString("XYZ:"..x..","..y..","..z) outputDebugString("RXRYRZ:"..rx..","..ry..","..rz) attachElements(element,vehicle,x,y,z) end end)
pa3ck Posted August 27, 2014 Posted August 27, 2014 If you're using attachElements, don't bother using getPositionFromElementOffset.. Just use: attachElements ( obj, obj2, 0, 0, 3, 0, 0, 0 ) -- x, y, z, rotx, roty, rotz
Karuzo Posted August 27, 2014 Author Posted August 27, 2014 Would it be on the same position on every single car? Since i need the exact back of a car.
Et-win Posted August 27, 2014 Posted August 27, 2014 Well every car is different, eh? ~Scripts~ Clan War System V1.2.0 ~Maps~ [DM]Et-win - The Run [FUN]Et-win - Drift Rocket [FUN]Et-win - Drift Rocket // [DD]Et-win - Cross 3xC
Karuzo Posted August 27, 2014 Author Posted August 27, 2014 Well every car is different, eh? That's what my problem is.
Et-win Posted August 27, 2014 Posted August 27, 2014 There must be a way to get the vehicle's upper length, somehow... ~Scripts~ Clan War System V1.2.0 ~Maps~ [DM]Et-win - The Run [FUN]Et-win - Drift Rocket [FUN]Et-win - Drift Rocket // [DD]Et-win - Cross 3xC
./BlackBird# Posted August 27, 2014 Posted August 27, 2014 Not sure if it's work perfect function getVehicleHeight(veh) if ( isElement(veh) and getElementType(veh) == "vehicle" ) then local x,y,z = getElementPosition(veh) local a = 0 while ( not isLineOfSightClear(x,y,z+a-0.1,x,y,z+a,false,true,false,false,false) ) do a = a + 0.1 end return a end return false end local x,y,z = getElementPosition(vehicle) local x = getVehicleHeight(veh) local Height = x+z #~BlackBird~#
Moderators IIYAMA Posted August 28, 2014 Moderators Posted August 28, 2014 If the vehicle doesn't have a collision somehow, you just got yourself an infinity loop. Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
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