Slastraf Posted December 12, 2015 Share Posted December 12, 2015 Above the current state of my turret placing. As you can see you can place turrets all over the place, but I want to make a grid like below. I already have generated pivots on a 10*10 field that also represent the waypoints of the Enemy Ai. But how can I make the turret placing like in a known turret defense game ? Also what are good shaders to make the turret like its not placed yet but visible (something like wireframe)? Quote Link to comment Share on other sites More sharing options...
Ma-Shell Posted December 12, 2015 Share Posted December 12, 2015 For placing the turrets, you should multiply their positions with their widths. This means, you should differentiate between grid-coordinates and world-coordinates. So, say your turrets are 10 leadwerks-units wide, then your grid-point (0,1) would correspond to world-coordinates (0,10). The grid-point (9,8) would correspond to the world-coordinates (90,80), etc. This also means, when you are in the process of placing the turret, you should derive their grid-coordinates from world-coordinates by dividing the world-coordinate by the width, while rounding down, i.e., the world-point (94,83) would belong to the grid-point (9,8) and therefore the turret would be placed at (90,80). I hope, you can see, what I'm trying to say. 1 Quote Link to comment Share on other sites More sharing options...
Rick Posted December 12, 2015 Share Posted December 12, 2015 As Ma-Shell is saying you have your 2D array grid and from there you can figure out the width and depth (the size) of your "tiles". They can be any size you want. Once you pick that information you can then look at your mouse pick position on the terrain and figure out what "tile" it was done in and then place the turret's position (assuming it's teh bottom center anchor) to the center of that "tile:. This is actually very common in 2D tile map systems so you can look at those examples online (for any language/engine) and see how that works. Here's a drawing to go from. This is how your 2D array "looks". The width of each tile in this example is 4 units wide and 4 units depth. The 0,0 at the top left would be the origin of the 3D world (in this example). So this would be the bottom right coord so going right is in the positive direction and z is the negative direction. You can obvious pick whatever coordinates you want to start with but this makes it easy to understand at first. https://www.dropbox.com/s/1wwhg961c5xzl8c/grid.png?dl=0 No let's say you mouse pick at position x = 3 z = 2. To find out what "tile" you clicked in you do the simple math equation: col = x / width row = z / depth You then ONLY take the whole number part and ignore any decimals. This will tell you the 2D array position you clicked. So in our example it's: col = 4 / 3 col = 0 (remember we want to ignore the decimal part) row = 2 / 4 row = 0 (remember we want to ignore the decimal part) So this is row = 0, col = 0 or (0,0) or the first tile position. Once we get the tile position we can calculate it's center point since we know the width and depth of each tile. Simply multiply the row by the depth and the col by the width and that'll give you the top/left position of that tile. So then to get the center you add (or subtract depending on the quadrant) half of the width or depth (2 in this example). So now you can convert from both tile position to world position and world position to tile position. To have your grid placed anywhere you just apply x and z offset values and add/subtract that offset value to every value you get and that lets you place your grid anywhere in the 3D world. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.