How do I make the same sprite object target another isntance that is not itself?

0 favourites
  • 8 posts
From the Asset Store
2D fighting template based in the game that defined the fighting games genre.
  • Hi, i'm trying to make a simple game where characters walk around (they are controlled by the pathfinding behaviour, not controled by players) and i'm with an issue, i wanna make an object called "character" move towards another instance of the tpye "character" when they get in range.

    Example:

    All of these are the same sprites but with different variables.

    I want them to targent each other when any of them enter the LOS, and once they either kill the opponent or lose the track of them, they just go back to the "wander" state, where they randomly walk around trying to find people.

    I've tried the los behaviour, the turret behaviour and even tried making my own custom LOS object but nothing, they just stay stuck at either fight or wander state.

  • Oh ye, this might also help you guys understand what i want to do and maybe point out what i'm doing wrong.

  • I'm not nearly as technical as some of the other users on the forum, but the first thing that popped into my head was an instance variable. I feel like this is already a part of the engine though. Don't sprites automatically get an object idea on creation?

    As you create instances of these little guys, you have a number instance variable that increases for each instance. So the first character has ID = 1, the second character has ID = 2, and so on.

    Then, you do a check using a comparison. If Self.ID =/= Character.ID, maybe that would work? I haven't tested this but I'm just tossing out ideas.

  • Hi, that is what i've been trying, i got something to work but i can't get the "

    " to work, it constantly changes to the "fight" state if any of them is seeing each other, no matter how far they from each other.

  • I know that the way you have the code set up isn't picking things correctly.

    Like, if you had a player sprite and a block sprite, and when the player touches any block, it destroys the block. It doesn't destroy ALL the blocks, just the one you touch. That's because when you have the event "When Player collides with Block" it picks the specific player that touches the specific block. That's why only that block is destroyed.

    So notice that your code says "if any characters have a line of sight to any characters" essentially. You need to add another condition that weeds out stuff that you don't want.

  • I know that the way you have the code set up isn't picking things correctly.

    Like, if you had a player sprite and a block sprite, and when the player touches any block, it destroys the block. It doesn't destroy ALL the blocks, just the one you touch. That's because when you have the event "When Player collides with Block" it picks the specific player that touches the specific block. That's why only that block is destroyed.

    So notice that your code says "if any characters have a line of sight to any characters" essentially. You need to add another condition that weeds out stuff that you don't want.

    i managed to do this, and it works like you explained, it doesn't check if any or all, it checks for each one of them, now i gotta find a way to "invert" this code and check if there is no insance of characters on sight.

    also thanks your tips are simple but they are helping me figure out stuff by bits faster than i'd be able to do if i tried by myself.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • GUYS, i managed to do what i wanted :D, thanks for the help anyways.

    It works just fine now ^^

  • Very nice! Glad I could help out a little bit. I completely forgot about For Each, haha.

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