How do I divide two instances of a same object this way :

Get help using Construct 2

Post » Wed Sep 23, 2015 2:39 am

Hi guys :) ,

I'm working on a fighting game and there is something I can't do here. Lets start by explaining you what I would like to do.

So there are two fighters in my layout. The important thing is that they are the same object, there is only one type of character here. Fighters have several instance variables, including "Control" to define who controls them (0=Player 1, -1=Computer AI) and "Team" to define who they can attack or not, as I plan to put teamfights.
I divided my code in two main parts, the first is the actions of a Fighter (run, punch, jump, etc...) and the second one is what calls those actions : keyboard inputs if it is a player, and AI guidance if it is a computer playing.

I am stuck in this AI thing and it might be because I'm confused with picking. Lets simply start with trying to make a fighter run against another. It looks like this :

if Fighter | Control = -1 (#If the fighter is played by computer)

-Compare X : if Fighter X greater
than Fighter X : Simulate control "Left"

-Compare X : if Fighter X less
than Fighter X : Simulate control "Right"

I need the AI to choose a fighter that is in a different Team and is the nearest target available. Since all the Fighters are the same object, it goes much more complicated and I'm lost here. Any ideas of how to proceed ?

I hope my explanation is clear enough. I been watching tons of videos and stuff but I can't make it clear.

Thank you guys

Vega
B
24
S
5
Posts: 42
Reputation: 1,286

Post » Wed Sep 23, 2015 5:20 am

The easiest way to do it would be to create a family and put only the player sprites in it. That way you can pick two seperate instances independently. A side annoyance is you won't be able to access the instance variables from the family unless you recreate them as family variables, change over the events and remove the old ones.

So for example if you called the family "other" then your events could look like this:
Fighter: control = -1
Other: control = 0
Fighter: X < other.x
--- fighter: simulate left pressed


Another way to do it without a family would be to pick one fighter, save it's values to variables then pick the other fighters and compare with the variables. It's doable but is tedious.
B
94
S
33
G
113
Posts: 5,353
Reputation: 73,267

Post » Sat Sep 26, 2015 6:26 am

Hey man, I managed to do the "tedious" way, with a group and local variables. It works really well even if it was kind of a mess at first. Also I used the "pick nearest instance" to determine who the IA fighter focuses.

Thanks, your last sentences gave me that idea.
B
24
S
5
Posts: 42
Reputation: 1,286


Return to How do I....?

Who is online

Users browsing this forum: Lordshiva1948 and 12 guests