Swimer Posted October 13, 2022 Share Posted October 13, 2022 I have a point of my object that needs to be rotated towards another, considering all 3 directions (3D). This, I understand, needs to be solved mathematically. Link to comment
βurak Posted October 14, 2022 Share Posted October 14, 2022 (edited) hello, have you tried this function? maybe it will work for you https://wiki.multitheftauto.com/wiki/FindRotation3D Edited October 14, 2022 by Burak5312 1 Link to comment
Swimer Posted October 14, 2022 Author Share Posted October 14, 2022 4 hours ago, Burak5312 said: hello, have you tried this function? maybe it will work for you https://wiki.multitheftauto.com/wiki/FindRotation3D No, I haven't tried it yet. This function is on the wiki site itself, but nevertheless when I started googling I didn't find anything Link to comment
Hydra Posted October 14, 2022 Share Posted October 14, 2022 (edited) --// Quick Example local ped = createPed(0, 0, 0, 10) local vehicle = createVehicle(411, 10, 0, 10) function lookAtVehicle() local px, py, pz = getElementPosition(ped) local vx, vy, vz = getElementPosition(vehicle) local rx, ry, rz = findRotation3D(px, py, pz, vx, vy, vz) setElementRotation(ped, rx, ry, rz) end addCommandHandler("trot", lookAtVehicle) function findRotation3D( x1, y1, z1, x2, y2, z2 ) local rotx = math.atan2 ( z2 - z1, getDistanceBetweenPoints2D ( x2,y2, x1,y1 ) ) rotx = math.deg(rotx) local rotz = -math.deg( math.atan2( x2 - x1, y2 - y1 ) ) rotz = rotz < 0 and rotz + 360 or rotz return rotx, 0,rotz end this will make the ped to rotate and look at vehicle every time Edited October 14, 2022 by Hydra 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