How to create building system similar to Orcs Must Die?
Hello. First for all, sorry for my English, it's not my first language.
Currently I'm working on a small FPS/Tower Defence game. I want my tower building system to be similar to Orks Must Dies system, where player can build tower anywhere he wants on a specific surfaces. I added a new collision channel to my project to separate building and non-building surfaces. But i don't understand how to restrict tower placement to be inside of the building surface.
Basically i wan't if my tower to snap edge-to-edge if player tries to put tower to close to the edge of the surface. I hope couple of screenshots will describe it better than me ;-)
Right now i'm able to put tower outside of surface, as shown at the first screenshot, but i want it to be snapped to the edge in such situations similar to how it shown at the second screenshot.
What is the right way to do what i want? I found a BP function "Find Closest Point on Line", but couldn't find built-in C++ method for this.
I understand now. Sorry for my part of the confusion, too — I realize I was also using some ambiguous language. Plus, I guess I misremembered how Orcs Must Die handles this, probably because it's been a couple years since I last played it.
Anyway, I think I know how you can make it work, no matter how large or small your traps are, or what size your grid is.
Basically, you'll still do a raycast to see what's under the cursor, but you'll also want to do four more raycasts to make sure the trap will fit in that location: one from each corner of your trap toward the surface that it's trying to attach itself to.
As long as:
...then you've found a valid location to put the trap.
If you want your traps to snap to a grid, say every 100 units, you'll need to perform another raycast to ensure the snapped location is also valid for trap placement, before doing the corners tests. If the snapped location is valid, you can move the trap to that location and then do your corners raycasts to make sure the trap actually fits in that location.
(Okay, you don't need to actually move your trap to perform the corners raycasts, but it's easier to describe and imagine it that way for now. But it really would be better to not move the trap until all of the raycasts are done, and all of them succeeded, or else you may end up moving the trap twice in the same update.)
Hopefully that makes sense. If you want a rough code example, I can try to write one up. I just thought I'd toss the overall idea at you and see what you thought first.
Follow this question
Once you sign in you will be able to subscribe for any updates here