can't get this code to work

Discussion and feedback on Construct 2

Post » Fri May 20, 2016 5:40 am

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
Last edited by Sir LoLz on Sat May 21, 2016 6:13 am, edited 1 time in total.
B
14
S
5
Posts: 54
Reputation: 1,061

Post » Fri May 20, 2016 10:48 pm

Based on pick nearest.

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

Maybe later i make you one based on distance.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sat May 21, 2016 4:59 am

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
B
14
S
5
Posts: 54
Reputation: 1,061

Post » Sat May 21, 2016 9:36 am

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.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sat May 21, 2016 10:17 am

Here you go

https://
drive.google.com/open?id=0B1SSuCVV8v74ZkI4RGFGUkd1ekU
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Tue May 24, 2016 5:02 am

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!
B
14
S
5
Posts: 54
Reputation: 1,061

Post » Tue May 24, 2016 12:41 pm

Last example is not that much tough ?
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Tue May 24, 2016 5:58 pm

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
Sea Monsters template - Isometric
Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705
B
43
S
14
G
12
Posts: 626
Reputation: 9,455

Post » Tue May 24, 2016 6:57 pm

@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.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Tue May 24, 2016 8:44 pm

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.
B
14
S
5
Posts: 54
Reputation: 1,061


Return to Construct 2 General

Who is online

Users browsing this forum: daksamedia and 2 guests