matin Posted March 30, 2020 Share Posted March 30, 2020 Hey guys , i create some colShape using createColRectangle i want when this event run onColShapeLeave back player to colShape Position and i try this : local x2,y2,z2 = getElementPosition ( hitElement ) setElementPosition(hitElement,x2 - 4 ,y2 - 4, z2) its work but some times in specific positions , It works the opposite and send player out of colShape Link to comment
The_GTA Posted March 30, 2020 Share Posted March 30, 2020 Hello matin, this looks like a mathematical problem. What you want to calculate is the line intersection between the player position and a 2D rectangle. But I don't know where exactly the player should be dragged back to. Do you want push the player toward the center of the rectangle? Or do you want to pick the closest distance to the rectangle? Link to comment
matin Posted March 30, 2020 Author Share Posted March 30, 2020 (edited) @The_GTA i just want example back player to his 1 second ago position i just want dont let him leave , but i dont want teleport him to Center of Shape just close area near him Edited March 30, 2020 by matin bad english Link to comment
The_GTA Posted March 30, 2020 Share Posted March 30, 2020 (edited) 8 minutes ago, matin said: @The_GTA i just want example back player to his 1 secend ago position i just want dont let him leave , but i dont want teleport him to Center of Shape just close area near him This is not that hard. If the player was already inside of the rectangle then you can remember his last position inside it and just reset him back to that position, like... local last_valid_player_pos = {}; local shape; -- the colshape. setTimer( function() for m,n in ipairs(getElementsByType("player")) do if (isElementWithinColShape(n, shape)) then last_valid_player_pos[n] = { getElementPosition(n) }; else local last_valid_pos = last_valid_player_pos[n]; if (last_valid_pos) then setElementPosition(n, unpack(last_valid_pos)); end end end end, 1000, 0 ); If you want to handle vehicles aswell then you have to extend the script. You also should handle the case if the script is started when the player was never inside the rectangle. Edited March 30, 2020 by The_GTA Link to comment
matin Posted March 30, 2020 Author Share Posted March 30, 2020 @The_GTA nice idea this code dosent help me much but this idea with timer i think use it thank you so much 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