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

0 favourites
  • 3 posts
From the Asset Store
112 High-Quality destruction sounds for videogames
  • 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


  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)