Hoit Posted December 21, 2015 Share Posted December 21, 2015 Hey guys I'm trying to write a piece of code that will build a wall around a turf tile once it's placed. But the problem is, that it depends on where the mouse was clicked (so the wall can have different positions even if the tile is the same, but mouse was clicked in different corners of it). I get coordinates from the pt variable, how can I get the coordinates of the turf block under that point?This is the code that builds the wall:local function ondeployturf(inst, pt, deployer) -- ... local x = math.floor(pt.x) - 3.5 local z = math.floor(pt.z) - 3.5 for i=1,7,1 do for j=1,7,1 do if i == 1 or i == 7 or j == 1 or j == 7 then local wall = GLOBAL.SpawnPrefab("wall_wood") wall.Physics:Teleport(x + i, 0, z + j) end end endendThanks a lot! Link to comment Share on other sites More sharing options...
ZupaleX Posted December 21, 2015 Share Posted December 21, 2015 You can use Transform:GetWorldPosition() on the turf instance. Link to comment Share on other sites More sharing options...
Mobbstar Posted December 21, 2015 Share Posted December 21, 2015 (edited) You can use Transform:GetWorldPosition() on the turf instance. I don't think so... I don't think ground tiles count as instances. This probably implies modulo mathemagic. You know, the x%4 thing that returns something 0-3 (base four). EDIT: Besides, those for loops are cringeworthy. Sorry, but it's really badly done. Change the third number to 7, so it begins with 1 and skips straight to 7 next turn. EDIT2: I'm an idiot when I am tired. Don't judge. Edited December 22, 2015 by Mobbstar Link to comment Share on other sites More sharing options...
Hoit Posted December 21, 2015 Author Share Posted December 21, 2015 I don't think so... I don't think ground tiles count as instances. This probably implies modulo mathemagic. You know, the x%4 thing that returns something 0-3 (base four). EDIT: Besides, those for loops are cringeworthy. Sorry, but it's really badly done. Change the third number to 7, so it begins with 1 and skips straight to 7 next turn. So is a turf placed every 4 positions? I'll try to use that to calculate. Which third number, the increment? But then it won't do what I need, I need it to loop 7 times, to place walls along the sides, not just the corners (what will happen if I jump straight from 1 to 7) Link to comment Share on other sites More sharing options...
Hoit Posted December 21, 2015 Author Share Posted December 21, 2015 (edited) You can use Transform:GetWorldPosition() on the turf instance.Did not work I don't think so... I don't think ground tiles count as instances. This probably implies modulo mathemagic. You know, the x%4 thing that returns something 0-3 (base four). EDIT: Besides, those for loops are cringeworthy. Sorry, but it's really badly done. Change the third number to 7, so it begins with 1 and skips straight to 7 next turn. Tried various things withx = x - (x % 4)z = z - (z % 4)But did not get what I wanted :/ It seems to align the walls with the turf tiles, but rarely puts it on the correct tile, usually the tile next to it depending on the position where it was clicked to place a turf (within the tile). Is there a way to see x/z position of the mouse or the player in-game? Edited December 21, 2015 by Hoit Link to comment Share on other sites More sharing options...
Hoit Posted December 21, 2015 Author Share Posted December 21, 2015 Got it to work by rounding to nearest 4s, thanks for help guys-- Round to nearest 4s local x = math.floor((pt.x / 4) + .5) * 4 local z = math.floor((pt.z / 4) + .5) * 4 Link to comment Share on other sites More sharing options...
ZupaleX Posted December 22, 2015 Share Posted December 22, 2015 (edited) I don't think so... I don't think ground tiles count as instances. This probably implies modulo mathemagic. You know, the x%4 thing that returns something 0-3 (base four). EDIT: Besides, those for loops are cringeworthy. Sorry, but it's really badly done. Change the third number to 7, so it begins with 1 and skips straight to 7 next turn. I admit I read too fast the stuff and the make_turf is actually for the inventory item. EDIT: but I think you would have been able to retrieve the coordinates without redoing the rounding and the modulo like the way Klei did it in the ondeploy function of the turf inventory item with the GetTileCoordsAtPoint function Edited December 22, 2015 by ZupaleX Link to comment Share on other sites More sharing options...
Hoit Posted December 22, 2015 Author Share Posted December 22, 2015 I admit I read too fast the stuff and the make_turf is actually for the inventory item. EDIT: but I think you would have been able to retrieve the coordinates without redoing the rounding and the modulo like the way Klei did it in the ondeploy function of the turf inventory item with the GetTileCoordsAtPoint function As in use this one?local x, y = map:GetTileCoordsAtPoint(pt:Get())I tried, but it gives me completely different coordinates (last time I was 0,0,0 at world position but this returned me 178/178 or something similar). Link to comment Share on other sites More sharing options...
ZupaleX Posted December 22, 2015 Share Posted December 22, 2015 I did not test it out, just read the function and made a guess (thus the "I think" ) Link to comment Share on other sites More sharing options...
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