Lalalu Posted November 26, 2022 Share Posted November 26, 2022 (edited) Hello everyone, I need your help with something... I'm gonna show you a simple code (server-side) that creates a moving object with moveObject; function moveObjectTest(player) local x, y, z = getElementPosition (player) local r = getPedRotation(player) local object = createObject(8417, x+math.sin(math.rad(-r))*(1.5),y+math.cos(math.rad(-r))*(1.5),z-0.2, 0, 0, r) moveObject (object,700,x+math.sin(math.rad(-r))*25,y+math.cos(math.rad(-r))*25,z-0.3,0,50,0) end addCommandHandler ("move", moveObjectTest) I want to know how can I stop the object movement only when It hits Walls or Peds instead of using timer or x - y position, I mean, by detecting the impact with other collision and then the object stop moving (sorry for my english) Edited November 26, 2022 by Lalalu Link to comment
JAY.ANN Posted November 27, 2022 Share Posted November 27, 2022 As I'd do that - I'd create a collision, then attach it to the object, and added addEventHandler( "onClientColshapeHit" ) into the code. https://wiki.multitheftauto.com/wiki/OnClientColShapeHit Link to comment
Lalalu Posted November 27, 2022 Author Share Posted November 27, 2022 13 hours ago, JAY.ANN said: As I'd do that - I'd create a collision, then attach it to the object, and added addEventHandler( "onClientColshapeHit" ) into the code. https://wiki.multitheftauto.com/wiki/OnClientColShapeHit Thank you, I will try with that Link to comment
alex17" Posted November 27, 2022 Share Posted November 27, 2022 local data = {} function moveObjectTest(player) local x, y, z = getElementPosition (player) local r = getPedRotation(player) data.object = createObject(8417, x+math.sin(math.rad(-r))*(1.5),y+math.cos(math.rad(-r))*(1.5),z-0.2, 0, 0, r) data.marker = Marker(x, y, z, "corona", 1, 255, 255, 255, 0) data.timer = setTimer(onObjectStop, 700, 1) attachElements(marker, object) addEventHandler("onMarkerHit", data.marker, collision) moveObject (object,700,x+math.sin(math.rad(-r))*25,y+math.cos(math.rad(-r))*25,z-0.3,0,50,0) end addCommandHandler ("move", moveObjectTest) function collision(element, samedim) if dimension then removeEventHandler("onMarkerHit", data.marker, collision) killTimer(data.timer) destroyElement(data.marker) stopObject ( data.object ) end end function onObjectStop() removeEventHandler("onMarkerHit", data.marker, collision) destroyElement(data.marker) end you can use a marker to detect elements colliding with the object 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