Brainstorming on real time building placement.
by Jason Gossiaux · in Torque Game Engine · 04/20/2008 (8:58 pm) · 4 replies
So for my semi RTS game I've just about finished my building placement system. You click the button for the building you want to place and then wherever your mouse moves on the screen a texture representing the outline of the building is drawn on the terrain. It moves with the mouse, and if you hold down the right mouse button it can be rotated.
Now the catcher here is detecting what is a valid and a non valid placement. Right now I just do a simple raycast from the center of the texture from above and make sure there's nothing but terrain underneath. If there is then the outline turns from green to red to indicate you can't place a building there. The problem is I need to detect collisions throughout the entirety of the floorplan as well as uneven terrain.
So my current plan is to brute force it. For the time being I'm just using square buildings to simplify it. I was going to do a series of raycasts down from above spread out acrossed the floorplan (of course, rotating each one to match the rotation of the floorplan... which is a lot of work). If it hits the terrain I know there's no objects obstructing it. Then I was going to do really short raycasts in an attempt at ensuring the ground is level enough to build on... also a lot of work.
Can anyone think of a simpler method for what I want to do? I suspect I might be missing some obvious solution that would greatly simplify things. I thought about actually placing the object for a moment and checking its collisions but deemed it too disruptive. I was thinking of using container finds but those tend to be circular, not square.
Well, I'm just wondering if anyone has an idea. This is quite the little project :P Thanks!
Now the catcher here is detecting what is a valid and a non valid placement. Right now I just do a simple raycast from the center of the texture from above and make sure there's nothing but terrain underneath. If there is then the outline turns from green to red to indicate you can't place a building there. The problem is I need to detect collisions throughout the entirety of the floorplan as well as uneven terrain.
So my current plan is to brute force it. For the time being I'm just using square buildings to simplify it. I was going to do a series of raycasts down from above spread out acrossed the floorplan (of course, rotating each one to match the rotation of the floorplan... which is a lot of work). If it hits the terrain I know there's no objects obstructing it. Then I was going to do really short raycasts in an attempt at ensuring the ground is level enough to build on... also a lot of work.
Can anyone think of a simpler method for what I want to do? I suspect I might be missing some obvious solution that would greatly simplify things. I thought about actually placing the object for a moment and checking its collisions but deemed it too disruptive. I was thinking of using container finds but those tend to be circular, not square.
Well, I'm just wondering if anyone has an idea. This is quite the little project :P Thanks!
About the author
#2
RTS(s), even those with 3D terrain, seem to often divide the terrain into some sort-of tiles. Since TGE doesn't have any concept of terrain tiles, you could either make a tile-based terrain editor ( lot of work ). Or look for a way to divide a hand-made terrain INTO tiles.
Once you have your terrain divided into abstract tiles, placing a building should be a simple as determining that all the tiles at the floorplan are buildable. Well, that and also dealing with dynamic obstacles - such as other buildings or units that could be "in" the floorplan.
But building a tile-abstraction for your terrain is not going to be trivial. Although I think it sounds like fun personally '-)
You could perform raycasts over your terrain in advance, like building a navigation grid. But in this case you are looking for valid building spots, eg, normal of the terrain is not too high and no static-obstacles. Also perhaps a min-max height deviation within the tile ( if you raycast its four corners ). It would also be handy to be able to designate tiles manually to correct any problems the algorithm runs into.
Note:
You might consider flattening the terrain wherever the building is placed... Perhaps this is always done just to make it look better, but the terrain still must be within the reqs. to place the building there to begin with.
04/21/2008 (9:35 am)
This could require a complex solution, rather than a simple one...RTS(s), even those with 3D terrain, seem to often divide the terrain into some sort-of tiles. Since TGE doesn't have any concept of terrain tiles, you could either make a tile-based terrain editor ( lot of work ). Or look for a way to divide a hand-made terrain INTO tiles.
Once you have your terrain divided into abstract tiles, placing a building should be a simple as determining that all the tiles at the floorplan are buildable. Well, that and also dealing with dynamic obstacles - such as other buildings or units that could be "in" the floorplan.
But building a tile-abstraction for your terrain is not going to be trivial. Although I think it sounds like fun personally '-)
You could perform raycasts over your terrain in advance, like building a navigation grid. But in this case you are looking for valid building spots, eg, normal of the terrain is not too high and no static-obstacles. Also perhaps a min-max height deviation within the tile ( if you raycast its four corners ). It would also be handy to be able to designate tiles manually to correct any problems the algorithm runs into.
Note:
You might consider flattening the terrain wherever the building is placed... Perhaps this is always done just to make it look better, but the terrain still must be within the reqs. to place the building there to begin with.
#3
04/21/2008 (12:24 pm)
I'd considered the flattening approach. I guess what worries me is the complexity of real time terrain editing in a MP environment. I've not seen many resources on the matter and while the editor shows terrain editing, it doesn't appear to be MP compatible.
#4
But if you only need to network terrain changes, and only one specific kind, it shouldn't be too complicated really. Anyhow - if you design your terrain to be relatively flat in certain areas that you want to allow building - then you don't really need to do this anyway.
Heres an idea, the building itself can contain the code to flatten the terrain. Then when the building is ghosted it should be at the same position for the server and all clients, then the terrain changes on each comp. should be identical - no need to ghost the terrain changes.
04/21/2008 (12:28 pm)
Someone posted a networked-multi-user version of the world editor not too long ago...But if you only need to network terrain changes, and only one specific kind, it shouldn't be too complicated really. Anyhow - if you design your terrain to be relatively flat in certain areas that you want to allow building - then you don't really need to do this anyway.
Heres an idea, the building itself can contain the code to flatten the terrain. Then when the building is ghosted it should be at the same position for the server and all clients, then the terrain changes on each comp. should be identical - no need to ghost the terrain changes.
Torque Owner Nathan Kent