PlayMaker Help & Tips > PlayMaker Help

Tower Defense game

(1/2) > >>

Mark_T:

One of the projects I`m working now is a tower defense game.
Well, to be honest I`m in the starting phase, and right now  I`m trying to see how this would be possible with Playmaker. This is one of the reasons I was happy seeing JeanFabre`s new Pool Manager 2 actions, which it`ll come very handy to spawn the creeps/units. My biggest problem so far is handling the towers AI: detecting the incoming units, firing to the proper units in the tower`s fire range, etc.
Any help in the right direction will be highly appreciated. :)

Cheers,

speedything:
There's probably quite a few ways to achieve this. If I was making it I'd probably do something like...

1. Make a detector sphere, and set the collider to "Trigger"
2. Create an FSM and add two states - "Not_Firing" and "Firing"
3. Use the "Trigger Event" action to switch between the two. When a unit enters the detector it will trigger the "Firing" state and when it leaves it will return to "Not_Firing". It will also store the collider object.
4. Somewhere else (maybe the same FSM or another one altogether) you're going to have to track the collider object with Get Position and use this to aim your bullets. The toughest bit will be predicting where it will be when the bullet hits, but I imagine there's some help on how to do this elsewhere on the net.
5. You will also have to be aware of the objects in the trigger radius so that it moves to the next when the first one enters.

Having written all that maybe (to take multiple enemies into account) it would be best to add an FSM to each one and reverse the system. They area the ones looking out for the trigger event and when they hit it they tell another FSM (on a different object) that they,
a. Are in the range of a tower
b. What tower they are in the range of
c. What there priority is (e.g. toughest, fastest, etc.)

This FSM will then get the postion of the highest priority one and then tell the tower to fire at that one until it dies or leaves the radius.

Mark_T:
Thanks speedything.
I was thinking the triggers way will the first one to try.
I`m not a coder, so no fancy tricks here. :)
Considering I might have in one moment 100 units and 100 towers on the map, my fear is that it might be a bit expensive.I don`t know, I`m just guessing here. My initial target are the mobile platforms.
Are there any other methods?

Again, thanks a lot for your input.
I`ll give it a go to see what I come up with.

speedything:
Mobile optimisation isn't my strong point, but the two things I can think of are -

1. Use "Get Distance" from each of your towers or units, but use it as infrequently as you can get away with.
2. Stick with the physics, but use the layers and Unity Physics settings to make sure that the units only have connections with detection zones - nothing else. (I was making a PC game with 1000s of people, and doing this not only sped it up significantly, but also stopped it crashing!)

Of course, 100s of towers and units has always got the potential to cause a few speed issues.

jeanfabre:
Hi Mark_t

 Bear with me for the pool manager 2 actions, When Unity and Playmaker will go out of beta, I will have more time to finalize them actions ( I have an issue with a pool manager action currently).

As for distance check, colliders are very performant, so don't fear using them ( and Speedything tips are definitely useful). If you really want to get the distance, use .sqrDistance instead, it will be quicker internally ( saves the square root expensive computation). If you know this from scratch, you simply have to raise your distance triggers variables to the power of two.

Bye,

 Jean



 Bye,

 Jean

Navigation

[0] Message Index

[#] Next page

Go to full version