darhal Posted June 25, 2015 Posted June 25, 2015 (edited) Hello all, This problem is hard to explain by the way I will post images it will explain better then words : here is my code : http://imgur.com/2p7DggD,L4yKIok,SH8KZ3f#0 -- work fine here http://imgur.com/2p7DggD,L4yKIok,SH8KZ3f#1 --this how I want it when the camera change poistion or rotation http://imgur.com/2p7DggD,L4yKIok,SH8KZ3f#2 -- this how it work in real --------------------------------- -- Utility functions --------------------------------- 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 ------------------------------------ -- End of Utility functions ------------------------------------ function controlObject() if not objectInEditor then return end if pressedButton == "num_8" then x,y,z = getMatrixForward(objectInEditor,0,moveSpeed,0) setElementPosition(objectInEditor, x, y, z) elseif pressedButton == "num_2" then x,y,z = getPositionFromElementOffset(objectInEditor,0,0-moveSpeed,0) setElementPosition(objectInEditor, x, y, z) elseif pressedButton == "num_4" then x,y,z = getPositionFromElementOffset(objectInEditor,moveSpeed,0,0) setElementPosition(objectInEditor, x, y, z) elseif pressedButton == "num_6" then x,y,z = getPositionFromElementOffset(objectInEditor,0-moveSpeed,0,0) setElementPosition(objectInEditor, x, y, z) elseif pressedButton == "pgup" then x,y,z = getPositionFromElementOffset(objectInEditor,0,0, moveSpeed) setElementPosition(objectInEditor, x, y, z) elseif pressedButton == "pgdn" then x,y,z = getPositionFromElementOffset(objectInEditor,0,0, 0-moveSpeed) setElementPosition(objectInEditor, x, y, z) end end addEventHandler("onClientRender", root, controlObject) in map editor this problem is already solved but I can t find the function that find the position Please help me guys this made me confused I already checked the forum evean the old posts and I cant find solution thx Edited June 27, 2015 by Guest #include <iostream> int main() { std::cout << "C++ is amazing <3" << std::endl; return 0; } I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please
Moderators IIYAMA Posted June 25, 2015 Moderators Posted June 25, 2015 I don't understand your images. 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
darhal Posted June 25, 2015 Author Posted June 25, 2015 Well I m making something like map editor it mean u can control objects via keys wich are arrow up arrow left arrow rightt etc... the pictures show how controles work fine for same camera sides and for some camera postion/rotation the element move to the wrong direction I want to fix this #include <iostream> int main() { std::cout << "C++ is amazing <3" << std::endl; return 0; } I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please
darhal Posted June 26, 2015 Author Posted June 26, 2015 guys any help ? #include <iostream> int main() { std::cout << "C++ is amazing <3" << std::endl; return 0; } I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please
Moderators IIYAMA Posted June 27, 2015 Moderators Posted June 27, 2015 local camera = getCamera () -- > getPositionFromElementOffset https://wiki.multitheftauto.com/wiki/GetCamera and subtract the distance, between camera and your offset of the camera. Add those to the mapeditor object. 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
darhal Posted June 27, 2015 Author Posted June 27, 2015 can you give me a simple example please ? #include <iostream> int main() { std::cout << "C++ is amazing <3" << std::endl; return 0; } I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please
Moderators IIYAMA Posted June 27, 2015 Moderators Posted June 27, 2015 Try something like this: function controlObject() if not objectInEditor then return end local camera = getCamera () local cameraX,cameraY,cameraZ = getElementPosition(camera) local objectX,objectY,objectZ = getElementPosition(objectInEditor) local x,y,z if pressedButton == "num_8" then x,y,z = getMatrixForward(camera,0,moveSpeed,0) elseif pressedButton == "num_2" then x,y,z = getPositionFromElementOffset(camera,0,0-moveSpeed,0) elseif pressedButton == "num_4" then x,y,z = getPositionFromElementOffset(camera,moveSpeed,0,0) elseif pressedButton == "num_6" then x,y,z = getPositionFromElementOffset(camera,0-moveSpeed,0,0) elseif pressedButton == "pgup" then x,y,z = getPositionFromElementOffset(camera,0,0, moveSpeed) elseif pressedButton == "pgdn" then x,y,z = getPositionFromElementOffset(camera,0,0, 0-moveSpeed) end if x then setElementPosition(objectInEditor, objectX+(x-cameraX),objectY+(y-cameraY),objectZ+(z-cameraZ)) end end addEventHandler("onClientRender", root, controlObject) I haven't build something like this before, so I have no idea how to script this perfect. 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
darhal Posted June 27, 2015 Author Posted June 27, 2015 OMG ! WOW ! thanks IIYAMA! you are amzaing everytime I stuck in something you help me thx bro <3 #include <iostream> int main() { std::cout << "C++ is amazing <3" << std::endl; return 0; } I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please
Moderators IIYAMA Posted June 27, 2015 Moderators Posted June 27, 2015 np. I wasn't sure if it would do what you wanted, but it seems it did. 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
darhal Posted June 27, 2015 Author Posted June 27, 2015 Yes it do thx a lot #include <iostream> int main() { std::cout << "C++ is amazing <3" << std::endl; return 0; } I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please
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