can't get this code to work

0 favourites
  • 10 posts
From the Asset Store
Two levels with two sistem Wave. with Source-code (.c3p) + HTML5 Exported.
  • Hello.

    I need to be able to have entities inside the same family to be able to attack each other. I can't do this with the hit box because I use that for navigation. (it only covers there feet to allow them to be drawn over walls.)

    My idea was to use an image point on the hand to see if it is within a distance of a body image point that would be on the target. and if so to then do attack stuff.

    however my code will not pick an instance other than itself. and if I put a condition to exclude itself it will then never pick anything.

    I'm sure it must be something simple. But for the life of me I can't figure it out.

    thanks

    (note that I changed the numbers in the distance check to see if it would pick anything up. as such that would be changed later once this code works)

    https://www.dropbox.com/s/db5gmma099x628k/code.PNG?dl=0

  • Based on pick nearest.

    https://

    drive.google.com/open?id=0B1SSuCVV8v74RTZ1dlloN0lTelE

    Maybe later i make you one based on distance.

  • Oh wow. That was more work than I expected. Thank you.

    edit:

    well it still does not work. I'm baffled. I pretty much copied your code. but the instance still picks itself. I don't get it.

    https://www.dropbox.com/s/59v3zq5o2e2hvvf/code.PNG?dl=0

  • Are there differend 'sprites' in the 'humans' family ? And therefor you can't pick the nearest by its 'instance name' (instead of using the family name as you do now) ?

    Anyway. Its a bit of a dirty trick anywayz. I wanted to show you how to go for a 'distance map' solution.

    But, if youre humans family contains differend sprites (not just a family of one sprite) then i have to retink this. Probaly need two familes.

    The nearest family member (or instance) to the postition of a member (or instance) is that member on that position. Got to work arround something that is in base totaly logic. And its not that much work.

  • Here you go

    https://

    drive.google.com/open?id=0B1SSuCVV8v74ZkI4RGFGUkd1ekU

  • thank you! finally got it to work!

    can't believe how hard picking the second closest instance was. feels like it should have been easier... oh well truth is stranger than fiction.

    Thanks again!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Last example is not that much tough ?

  • umm.. pick nearest? do you want really to pick nearest? what kind of game is it ? do your entities shoot range? or just melee? what if 2 instances are on the same distance from different sites, pick nearest will random. also if one is closer, it will pick the closest, but do you want the one attacking to get picked or the one closest..

    you didn't elaborate your problem really much.. you just said you want your objects from a family to attack each other

  • saiyadjin, positions in C2 are decimals. Distance is A^2=B^2+C^2. A,B beeing decimals, C beeing like 'super' decimal as a result.

    Small chance that two sprites will be on the same distance. Very small.

  • It was enough 99.

    saiyadjin

    I already had code for what I want them to do. but because objects in the same family will be able to attack each other I needed a way to pick a second closest instance to an instance of the same family. So that way the attacker would not attack itself.

    True I did not elaborate. I really did just want an instance to be able to pick another instance of it's own family. I guess I did not know what else to say.

    It is a melee attack.

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