playMaker

Author Topic: [SOLVED] Ranged and melee combat for 2D strategy game  (Read 6908 times)

bizilux

  • Full Member
  • ***
  • Posts: 171
[SOLVED] Ranged and melee combat for 2D strategy game
« on: September 02, 2013, 09:01:08 AM »
Hello all...

im trying to make 2D side view, strategy game for browsers... basically you have your base on left side, enemy base on right side, and both keep sending troops from one side to other, trying to win... (similar genre: http://armorgames.com/play/4071/warfare-1944 ) well mine is with zombies.

anyways, what im having problem with...

i programmed soldier to shoot at zombies, it uses raycast (distance 7) to determine if there is any zombie in that area, and when it is, it stops and spawns bullets and sends them towards zombies... thats fairly simple... and zombies have trigger event that destroys bullet and removes health from them.

but now here is the catch, when that soldier gets overrun by zombies, for example 10 zombies attack a soldier, those 10 zombies all have raycasts too, and they all stop at distance 1, from soldier (for melee attacking)


then soldier attacks multiple zombies at once, because all zombies are aligned in a line (distance 1 from soldier). and all zombies have trigger event, and when that bullet reaches that line where zombies are, it damages all zombies standing at distance 1 from soldier... i dont want it like that, i only want it to hit 1 zombie...

so any ideas how to do that? there must be a way but im not seeing one... :/


the only solution that i came up with, was to generate random number from 0.8-1.2 and then use that for zombie raycast, and then they would stop at different distances from soldier, but there's got to be nicer solution than that...

attachment 1: shows how soldier FSM is set up, and shows how raycast is set up
attachment 2: shows how zombie Trigger FSM is set up, that detects bullets and destroys them and removes health
attachment 3: shows how zombie raycast is set up...




after i get the answer... i will try to do it for melee combat too, because it has the same problem
« Last Edit: September 13, 2013, 09:36:07 AM by bizilux »

bizilux

  • Full Member
  • ***
  • Posts: 171
Re: Ranged and melee combat for 2D strategy game
« Reply #1 on: September 03, 2013, 03:04:35 PM »
bump?

anyone got suggestion how to make better ranged & melee combat?

bizilux

  • Full Member
  • ***
  • Posts: 171
Re: Ranged and melee combat for 2D strategy game
« Reply #2 on: September 04, 2013, 03:53:20 PM »
let me rephrase the problem...

when enemies (in my case zombies) are in a line, lets say they stop at melee distance from my player.

then the bullets from player, hit all zombies, because they are in a line and they all trigger that bullet...



i dont want it like that, i just want the player to hit 1 enemy, not all of them, even if they are in line...

how on earth do i solve that?

i attached my new zombie trigger FSM...

but basically the problem is that when zombies align up, they have box colliders at the same place thus, the bullet hits triggers events on all zombies, instead of just one
« Last Edit: September 04, 2013, 04:15:41 PM by bizilux »

bizilux

  • Full Member
  • ***
  • Posts: 171
Re: Ranged and melee combat for 2D strategy game
« Reply #3 on: September 05, 2013, 10:46:58 AM »
like really no-one has any ideas how to do combat for 2D sideview game? ...

or any game for that matter where enemies can overlap eachother? and you only want to hit 1 enemy even if they are on top of eachother
« Last Edit: September 05, 2013, 11:03:08 AM by bizilux »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Ranged and melee combat for 2D strategy game
« Reply #4 on: September 05, 2013, 08:45:05 PM »
It's a tricky problem because there are many situations where you want overlapping triggers to all get the event.

Can you use rigid body collisions instead of triggers, to keep your enemies spaced out and not overlapping? Or is the overlapping part of the design?

Or you could put the trigger event on the bullet, so it gets the first thing it hits, then use Send Event to send a Hit event only to that object. You can use Set Event Data and Get Event Info to associate extra data with the hit event.

bizilux

  • Full Member
  • ***
  • Posts: 171
Re: Ranged and melee combat for 2D strategy game
« Reply #5 on: September 05, 2013, 09:05:18 PM »
thanks for pointing me in right direction...

Quote
Or you could put the trigger event on the bullet, so it gets the first thing it hits, then use Send Event to send a Hit event only to that object. You can use Set Event Data and Get Event Info to associate extra data with the hit event.

i've thought about putting trigger event on bullet... never went and actually did it. maybe it will work



Quote
Or is the overlapping part of the design?
overlapping is part of the design, basically humans go from left side of the screen to right side, and zombies go from right side to left side. its linear movement, so overlapping is needed here to basically allow zombies to over-run human, to all attack him at once.
« Last Edit: September 05, 2013, 09:40:58 PM by bizilux »

bizilux

  • Full Member
  • ***
  • Posts: 171
Re: Ranged and melee combat for 2D strategy game
« Reply #6 on: September 12, 2013, 09:35:09 AM »
ok so i have a problem... i cant seem to figure out how to pass information from bullet to target...

my set event data, and get event info are not setup correctly i believe...

for example: i want to specify that Bullet Tank will do 100 damage, and Bullet Soldier will do 10 damage, (Bullet soldier will have other FSM ofcourse...)
and when target gets hit, i want it to read what damage it was in a variable... 

basically i need to know how to attach more information to the bullet...

this is bullet tank trigger


this is bullet tank Send Event  (Set event data is not really working properly)


this is target right now... (Get event info is not really working properly)



1 more question...
you think theres gonna be a problem when there will be lots of bullets and each hitting their targets? because of global variable collider?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Ranged and melee combat for 2D strategy game
« Reply #7 on: September 13, 2013, 05:30:30 AM »
Hi,

 Have y look at this thread: http://hutonggames.com/playmakerforum/index.php?topic=4963.msg23328#msg23328

I created a package showing how to do this properly.

bye,

 Jean