Posted By
|
Message
|
[DELETED] Likes to put dots on paper
Registered 08/12/2008
Points 118
|
26th October, 2009 at 10:05:10 -
Okay, my only problem preventing me from moving forward in my tower defence engine is the towers targetting and attacking monsters that are travelling along a path.
It seems to have trouble selecting the right objects so much that I have to run a loop that checks every tower and whether a monster is in sight for them every 0.10seconds.
Let me give you some examples:
If I build one tower and one monster spawns, the tower WILL fire every 0.10 seconds at the creep. If more than one enemy is spawned, it still keeps the rate of fire pretty close to that.
If I build several towers, 2 or greater, and monsters spawn and travel the path, they seem to fire at random times, as if they all do checks but only one seems to fire.
I think the problem lies in my conditions for the event. Let me write it out so it makes more sense:
Every 0.10 seconds
run loop "checkrange" (Number of towers) times
On loop "checkrange"
+ ID of Tower = LoopIndex("checkrange")
+ Pick one of tower
+ Pick one of Creep
+ Distance between Tower and Creep is 50 or less
(Firing actions)
PROBLEMS:
If I take out Pick one of creep, then they will only fire at the last created instance of the Creep.
If I take out Pick one of tower, then towers will only fire when creeps are in range of the last created instance of the tower.
I can't win; I tried to narrow down object scope and it works but they are not firing at the rate of how often the fast loop is executed. I used spread values for IDs for towers so that each loop has a step for each tower so that each tower can be calculated; but if every tower is in range of one creep, they don't all rain hell down on it. It's like they have trouble trying to fire from more than one tower at a time. But the events don't suggest otherwise, you would think that each tower has its range checked and then fires if possible. What SHOULD happen with these events is that as a creep passes by, every 0.10 seconds at least ONE of the towers will be firing at the creep.
n/a
|
Assault Andy Administrator
I make other people create vaporware
Registered 29/07/2002
Points 5686
|
26th October, 2009 at 11:29:47 -
Personally, I don't think I would use your method for detecting which enemies are closest and which ones to shoot. It seems quite resource intensive. However I will try to point out the problems with your code and the solutions rather than tell you a new method from scratch.
Firstly, "Pick one of tower" should not be in there. This means that from the pool of all towers, MMF is picking a random tower. However you have already narrowed down the pool of objects to 1 tower with "ID of Tower = LoopIndex("checkrange")". So in essence you are saying: Pick towers where "ID of Tower = LoopIndex("checkrange")". And then from that 1 tower, pick a random tower - which of course does nothing but pick the tower you have already selected.
What you described with If I take out Pick one of tower, then towers will only fire when creeps are in range of the last created instance of the tower. sounds like it occurs because you may have forgotten to respread the ID value after creating a new tower. When a new tower is created you should spread the IDs again.
Your next problem is "Pick one of Creep". So we established before that in this loop you are going through tower by tower. The problem here is that you are not also looping through each enemy.
Take for example 3 towers, IDs = 1,2,3.
* Start loop, (First loop index = 1 for simplicity).
* On loop 1, choose Tower #1
* Tower 1 is selected, now randomly choose a creep.
* Is this creep close enough?
* Yes > Shoot
That's essentially what you've asked MMF to do. The problem there is that not every enemy is being checked. In fact since you're using a random function ("Pick one at random") it's possible that certain enemies are never checked to see if they're close to a tower. This explains "they seem to fire at random times, as if they all do checks but only one seems to fire. "
Some people would suggest that you should do a nested loop. So for every tower loop you should also start a loop which checks through every enemy. I'm sure you can see that this gets quite memory intensive once you have many towers and enemies. Eg. 10 towers and 20 enemies = 10 * 20 loops per 0.1 seconds (in your code) = 2000 fastloops per second.
Edited by an Administrator
Creator of Faerie Solitaire:
http://www.create-games.com/download.asp?id=7792
Also creator of ZDay20 and Dungeon Dash.
http://www.Jigxor.com
http://twitter.com/JigxorAndy
|
Assault Andy Administrator
I make other people create vaporware
Registered 29/07/2002
Points 5686
|
26th October, 2009 at 11:56:17 -
Boredom got the better of me. I whipped up this basic tower defence engine in 15 mins for you:
http://www.clickteam.com/epicenter/ubbthreads.php?ubb=showflat&Number=163615
Mirror: http://mfa.aquadasoft.com/view/1256558167-Basic_Tower_Defence_Assault_Andy
Creator of Faerie Solitaire:
http://www.create-games.com/download.asp?id=7792
Also creator of ZDay20 and Dungeon Dash.
http://www.Jigxor.com
http://twitter.com/JigxorAndy
|
[DELETED] Likes to put dots on paper
Registered 08/12/2008
Points 118
|
27th October, 2009 at 05:58:55 -
Damn it Andy, you're a genius. I've never used the Pick/count functions in MMF before so I really had no idea what I was doing
This Tower Defence game is on a fairly small scale so I don't think the looping will reach high enough to crash the application. And I would only be running these events when applicable, eg no point doing checks when there's no enemies on the frame.
Thanks so much for that!
n/a
|
Assault Andy Administrator
I make other people create vaporware
Registered 29/07/2002
Points 5686
|
27th October, 2009 at 09:58:16 -
You're welcome
Creator of Faerie Solitaire:
http://www.create-games.com/download.asp?id=7792
Also creator of ZDay20 and Dungeon Dash.
http://www.Jigxor.com
http://twitter.com/JigxorAndy
|
|
|