Hi, I'm continuing work on this RTS project but have run into another problem....
Currently I am trying to make a working enemies module that has option for both ranged and melee minions. The logic to make them move and attack has been done. The program on the press of the spacebar will spawn a minion that will go and attack the user
Problem is: seems that all the minions have the same x, y if you spam space. I dont know how to stop them all occupy the same space.
I also cant seem to make them spawn from the spawn point consistently. After the first minion is spawned they seem to spawn on that initial minions current location rather than at the spawn point.
what should be happening: after spawning at the spawn point minions move to engage the user. No enemies are overlapping and all occupy their own space around the user.
I hope this makes sense...any help is greatly appreciated! please let me know if you need any further info or if any of the code does not make sense )
PS feel free to use this code if you stumble across it. hope it helps
RTS enemies x, y position overlap from table
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 8
- Joined: Sat Jun 22, 2024 12:05 pm
RTS enemies x, y position overlap from table
- Attachments
-
- attempt1MinionOneVsOne.zip
- (16.11 KiB) Downloaded 326 times
Re: RTS enemies x, y position overlap from table
Code: Select all
function love.keypressed (key, scancode)
if key == "space" then
table.insert(listOfMinions, m1)
end
end
The m1 minion is defined in love.load() and you are not adding its values but the m1 reference itself.
I did this and it seems to work:
Code: Select all
function love.keypressed (key, scancode)
if key == "space" then
local newMinion = Minion(window_width * 0.9, window_height/2, 12, 100, 10, 120)
table.insert(listOfMinions, newMinion)
end
end
-
- Prole
- Posts: 8
- Joined: Sat Jun 22, 2024 12:05 pm
Re: RTS enemies x, y position overlap from table
ahhh its always the simplist things haha. Thank you so much!
I have some ideas to stop the overlap issue but can anyone explaing what #<a table> does over using ipairs<a table>
im not entirely sure but i think i need to do somehow iterate through the table using i,v in ipairs and get v+ 1 too, aka minion and the next minion along. Then itll be easy to work out if the x,y of each minion are overlapping....
I have some ideas to stop the overlap issue but can anyone explaing what #<a table> does over using ipairs<a table>
im not entirely sure but i think i need to do somehow iterate through the table using i,v in ipairs and get v+ 1 too, aka minion and the next minion along. Then itll be easy to work out if the x,y of each minion are overlapping....
Re: RTS enemies x, y position overlap from table
You need some "collision detection" and "collision reaction."
The units are circles, so as first step you need to figure out which circles overlap.
#table returns the number of elements in an array.
for-loops with #table or ipairs both work, but only if the array uses integer number as index and has no "holes."
[1][2][3][4] will work.
[1][2][7][10] will not loop as expected.
This will become relevant, if you delete destroyed units.
Either use pairs (not: ipairs) or if you deleted an element then move all other elements accordingly to fill the hole.
Hope that is useful for googleing, those are both quite common problems.
The units are circles, so as first step you need to figure out which circles overlap.
#table returns the number of elements in an array.
for-loops with #table or ipairs both work, but only if the array uses integer number as index and has no "holes."
[1][2][3][4] will work.
[1][2][7][10] will not loop as expected.
This will become relevant, if you delete destroyed units.
Either use pairs (not: ipairs) or if you deleted an element then move all other elements accordingly to fill the hole.
Hope that is useful for googleing, those are both quite common problems.
Who is online
Users browsing this forum: Amazon [Bot] and 1 guest