12p Posted October 20, 2011 Share Posted October 20, 2011 I want to create an element in front of the player, at exactly 15 units distance from it, How can I convert it so it fills the 15 units and nothing else? I have no idea how to do this. This is my code for getting the X, Y and Z coordinates: local x2, y2 = getPedTargetCollision ( getLocalPlayer ( ) ) if not x2 or not y2 then return end local x1, y1, z1 = getElementPosition ( getLocalPlayer ( ) ) local x = x1 + ( ( x2 - x1 ) / 3 ) --This gets the X position in front of player, but is relative to the collision. local y = y1 + ( ( y2 - y1 ) / 3 ) --This gets the Y position in front of player, but is relative to the collision. local z = getGroundPosition ( x, y, z1 + 10 ) (Don't care about getPedTargetCollision, I already made the script so it can fit the weapon needing) EDIT. getPointFromDistanceRotation doesn't work properly. Link to comment
Wojak Posted October 20, 2011 Share Posted October 20, 2011 x2, y2 = getPedTargetCollision ( getLocalPlayer ( ) ) if not x2 or not y2 then return end local distlimit = 16 local x1, y1, z1 = getElementPosition ( getLocalPlayer ( ) ) local realdist = getDistanceBetweenPoints2D(x1,y1,x2,y2) local percdist = distlimit/realdist local x = x1 + percdist*(x2 - x1) local y = y1 + percdist*(y2 - y1) local z = getGroundPosition ( x, y, z1 + 10 ) of course it may be wrong if the obstacle is closer than 16 units... Link to comment
12p Posted October 20, 2011 Author Share Posted October 20, 2011 Okay. Thank you very much, I'm gonna test it. Link to comment
karlis Posted October 20, 2011 Share Posted October 20, 2011 x2, y2 = getPedTargetCollision ( getLocalPlayer ( ) ) if not x2 or not y2 then return end local distlimit = 16 local x1, y1, z1 = getElementPosition ( getLocalPlayer ( ) ) local realdist = getDistanceBetweenPoints2D(x1,y1,x2,y2) local percdist = distlimit/realdist local x = x1 + percdist*(x2 - x1) local y = y1 + percdist*(y2 - y1) local z = getGroundPosition ( x, y, z1 + 10 ) of course it may be wrong if the obstacle is closer than 16 units... it should handle it correctly aswell. Link to comment
12p Posted October 20, 2011 Author Share Posted October 20, 2011 it should handle it correctly aswell. No need to bump the topic just to say that. The code works properly, Wojak. Thank you :B Link to comment
karlis Posted October 20, 2011 Share Posted October 20, 2011 i meant that he pointed out it wouldn't work with closer target, but in fact it does. Link to comment
Wojak Posted October 20, 2011 Share Posted October 20, 2011 i meant that he pointed out it wouldn't work with closer target, but in fact it does. i've meant, when you target the building standing next to it, you will get coordinates inside the building, i don't know how this sctipt will be used, so i din't know is that good or bad... other than that this is definitely not a complex math Link to comment
12p Posted October 20, 2011 Author Share Posted October 20, 2011 other than that this is definitely not a complex math Still not know how to properly use geometrical functions 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