Jump to content

What would be the best way to ...


Slastraf
 Share

Recommended Posts

What would be the easiest way to make a tower defense game ?

What would be the best way to make this in lua ?

I taught about a grid in the 3d world, that consists of x and y places to build towers.

But theres the problem that i want to make the navmesh visible, and a way to actually place the turrets there (i have no idea how to make the grid that stores information for each y and x field..

If you could think of a better way then please tell me, also how you could possibly program it.

Also here are some images of what direction my game could go in future (and for a better understanding)

 

 

_________

post-12189-0-49831000-1447334148.jpg

post-12189-0-33135100-1447334162_thumb.jpg

post-12189-0-84836100-1447334168.jpg

What I have already done:

Rts camera,

you can place boxes with the mouse into the world,

prefab spawning

Link to comment
Share on other sites

I think you mean x and z since we are in 3D not 2D.

 

So you only really need to be worry about the navmesh on the area they can walk. Since you don't place towers on the area you walk this should be fine.

 

So how to place towers depends on what time of game you want it to be. You could make a 100% free placement game where you have a "ghost" image of the tower and you check that it's AABB isn't intersecting with anything else before placing.

 

But theres the problem that i want to make the navmesh visible, and a way to actually place the turrets there

 

I'm not following what this means? You want the navmesh visible? Why would you want that? I must be misunderstanding that.

 

 

So the top pic and bottom pic are fairly easy because the path is dug into the terrain so the navmesh would only be able to walk on that path and not get up. The middle one is different because the navmesh would be able to move anywhere. To get around that you can place invisible csg around the path so the path generated is only the visible graphics path.

 

Note that using the LE navmesh process you might not get nice and neat enemy movement if they are layered. If they are sent 1 at a time it's fine but if you want 2-3 side by side that look like they are taking separate paths then it might not give you that. To get that you could play around with invisible CSG and make lanes on your visible path though.

Link to comment
Share on other sites

I want the player to also place the turrets in the way of the enemy, so it recalculates a new navmesh. if the navmesh doesnt go on the other site the turret cant be placed. thats why the navmesh should be visible, or at least a fake navmesh that is calculated before the actual one, to check if there is a way between the z,x fields.

 

I think i could even program this but i want to know how to store information in those fields or how to create them by code.

Link to comment
Share on other sites

Oh. None of those games above do that. I've never seen a tower defense game do that actually. My first thought would be are you sure that's what you want to do? I would be shocked to find out the navmesh information is available to lua. If anything that sounds like something you'd have to do in C++ and even then it may not be exposed?

Link to comment
Share on other sites

In a grid-based game you might want to skip the navigation of Leadwerks and use an algorithm like A*. It's probably easier in the long run as it is designed for grids. All you need is to make a variable for a tile whether it's walkable or not. The algorithm can do the rest.

 

Also to have physics-like behaviour, you can use forces to move an object instead of using GoToPoint().

 

If you really want Leadwerks' navigation then you can rebuild navigation on specific positions (if I recall correctly). Then you can keep using GoToPoint() and everything should be working from there. However, building navigation might take some processing time which can freeze your game for the duration.

Using Leadwerks Professional Edition (Beta), mainly using C++.

Windows 10 / Linux Mint, Visual Studio 2017. GPU: NVidia GeForce GTX970, CPU: Intel i7 7700K @ 4.20 GHz

Previously known as Evayr.

Link to comment
Share on other sites

I guess the OP wants something like http://store.steampowered.com/app/214360/

Yes, exactly. Firstly I would want to know how to store information for fields like 10x10 ,

every field has its position (x,z), if its built on (true/false).

If I did a TD game I'd lean towards A*.

Then I taught of an algorithm that always goes x+1 ,if the next x field is not moveable, then it checks the whole path for z+1 or z-1 and so on.

But I really have no Idea on how to make those Grids. Every cornerpoint has a pivot on it and the monsterai goes the path , always the next pivot with goToPoint.

What does one cell even consist of ?

How do I make it ?

Link to comment
Share on other sites

First off unless you are curious in learning how A* works I wouldn't worry about it. You can use that lib I posted and just get it working without knowing the details. If you want to learn how it actually works and try to implement it yourself then google it and learn, but pending your skills it could take time and you could have bugs to work through.

 

Generally you have a 2D grid array/table of either just booleans or other objects/tables if you need more information per grid. If you just want to know if that "tile" (we'll call it) can be walked on or not then boolean works (true/false). At some level you'll need walkable/not walkable anyway for the A* to know how to find the path for you.

 

The "tiles" in the 2D array/table have a center point to them, which is determined on how big you want the tiles to be. You will get back the tiles from the A* and then you move from center point to center point (generally) along those tiles.

 

 

That 2nd screenshot you have above gives you an idea of that as you can clearly see the tiles with those grassy areas. Those tiles exist in a 2D array of booleans/objects in the code. All but the roads are marked as not open. Now in that game they could have not done the A* and just did pivots connecting because it's less dynamic of a path, but they could have used A* to find the path. You just have to think of the 2D array/table separately from your actual gfx but try to somewhat line them up so they match. They just don't have to be exact and often games want to hide that. In your 2nd screenshot they aren't really trying to hide that and in that Tower Wars they aren't hiding it. A* can work on hex tiles as well as square tiles and clearly Tower Wars uses the hex tiles.

  • Upvote 1
Link to comment
Share on other sites

Script.counter = 0
function Script:Start()
cells = {}
cells.x= 10
cells.y= 10
self:BuildNavTiles()
end
function Script:BuildNavTiles()
for y=0,10 do
self:AddTile(Vec3(0+y,0,0))
for x=0,10 do
self:AddTile(Vec3(0+y,0,0+x))
end
end
end


function Script:AddTile(location)
--local colorVec=SetColor(163/255,30/255,22/255,1)
model= Pivot:Create()
local vector = Vec3
vector = location
model:SetPosition(vector.x, 0,vector.z)
self.counter = self.counter +1
end

I have this now. how do I save the pivots into the Array to proceed ?

Link to comment
Share on other sites

corrected it. above only makes 10 nodes in the end, overwrites while processing

function Script:BuildNavTiles()
--node= {}
for i = 1, 10 do
for j = 1, 10 do
local A = self.counter
node[A] = {}
node[A].x =j
node[A].y =i
node[A].iD=self.counter
node[A].pivot = self:AddTile(A)
self.counter=self.counter+1
end
end
end

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...