Check specific instances, not all of them together

Get help using Construct 2

Post » Fri Jun 29, 2012 6:37 pm

Greetings!

Just started working with Construct2, and I am loving it.

I have sprite called "Fish".

When I cast my "Hook", I pick a random instance of a fish (I have 5 at once) to go towards the hook at eat it. I also have an ability to "Recast", which destroys the hook.

What I want, is for that Fish to go back to it's original position, and I have that part already figured out; I grab their starting position in an instance variable when they are created, so they know where to go.

This is my event to tell if the fish is home or not:


My problem is, the engine seems to only set this once all the fish meet those conditions. I want to set it on a per-Fish basis. If one fish meet these conditions, set "AtHome" = true for that fish.

I've looked in the "How do I" page at the instance-specific guides, and I didn't see one that addressed this.

Thanks!
B
3
Posts: 7
Reputation: 314

Post » Fri Jun 29, 2012 6:56 pm

Try adding a "For each (fish)" condition in there. It's a system condition7Soul2012-06-29 18:57:22
B
83
S
21
G
15
Posts: 1,039
Reputation: 15,134

Post » Fri Jun 29, 2012 7:03 pm

Also, if you want your fish to stop when within 10 pixels of it's origin, instead of the 4 conditions, you can do it with only 1 if you use the distance expression.

Use "System: Compare two values", then input:

[code]distance(Fish.X, FishOriginX, Fish.Y, FishOriginY) < 10[/code]
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Fri Jun 29, 2012 11:25 pm

[QUOTE=7Soul] Try adding a "For each (fish)" condition in there. It's a system condition[/QUOTE]

EDIT:
I think I tried that before and it didn't help. Here is what I've got now:



Now the fish move to the hook, but when the hook gets destroyed by a recast, they just sit there.

EDIT: Alright, I saw the problem, I inverted that distance check when I shouldn't have. When I fixed that, their behavior is the opposite. The Fish now constantly try and get to their origin, even if they do get there, unless they are going after a Hook.



[QUOTE=Nimtrix] Also, if you want your fish to stop when within 10 pixels of it's origin, instead of the 4 conditions, you can do it with only 1 if you use the distance expression.

Use "System: Compare two values", then input:

[code]distance(Fish.X, FishOriginX, Fish.Y, FishOriginY) < 10[/code][/QUOTE]

Ah, thanks! Much cleaner.Nimble0052012-06-29 23:36:41
B
3
Posts: 7
Reputation: 314

Post » Fri Jun 29, 2012 11:34 pm

Hmm, do you think you could share your .capx through dropbox so we can have a look at the problem?

It makes everything so much easier when we can see what happens and fiddle with it.
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Fri Jun 29, 2012 11:43 pm

[QUOTE=Nimtrix] Hmm, do you think you could share your .capx through dropbox so we can have a look at the problem?

It makes everything so much easier when we can see what happens and fiddle with it.[/QUOTE]

Sure thing.

https://dl.dropbox.com/u/88631007/MyProj.capx
B
3
Posts: 7
Reputation: 314

Post » Fri Jun 29, 2012 11:54 pm

When you click the recast button, this is where you need the "For each" loop, or a "Pick all fish" condition.

Edited .capx: Nimble_Fishproblem.capx (r97)
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Sat Jun 30, 2012 12:37 am

[QUOTE=Nimtrix] When you click the recast button, this is where you need the "For each" loop, or a "Pick all fish" condition.

Edited .capx: Nimble_Fishproblem.capx (r97)[/QUOTE]

Ah, that makes sense, thank you much for taking a look. When you run it, do the "Fish" constantly move around their origin? I was trying to get them to stop moving once they reached their origin.
B
3
Posts: 7
Reputation: 314

Post » Sat Jun 30, 2012 12:49 am

Yep, it's because I've given you the wrong order in the distance expression.

It's supposed to be: distance(Fish.X, Fish.Y, Fish.OriginX, Fish.OriginY)

The for each/pick all I added earlier is unecessary, but you'll need a loop above the distance checks, like 7Soul said. I've updated the .capx in my previous post. Sorry, I'm a bit tired xDNimtrix2012-06-30 01:00:22
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Mon Jul 02, 2012 4:45 pm

Great! Thank you, I learn the best from examples, so this is very helpful.
B
3
Posts: 7
Reputation: 314

Next

Return to How do I....?

Who is online

Users browsing this forum: Braus, Draconinho, luisgmolina, Magistross, nedzad, nimos100, R0J0hound and 34 guests