Trouble with object instances

Get help using Construct 2

Post » Sun Nov 04, 2012 9:02 pm

I've got a little test level going where you control a ninja and there are bad ninjas that throw stars at you. I'm faking a raycast by having the bad ninja fire an invisible sprite at the player, and if it hits the player then fire a real ninja star. So basically the bad ninjas should only throw a ninja star if the player is not hidden by a wall. It was all working fine, but when I added a second bad ninja (copy and paste) both of them now fire at the player when any one of them has a clear shot. Can anyone explain what I am doing wrong and how to remedy this...it's driving me nutty!

I tried to add a link to the capx, but being new here it doesn't allow me for some reason!

Thanks! :)
B
5
Posts: 11
Reputation: 722

Post » Sun Nov 04, 2012 9:36 pm

Hmm... maybe if you assign a unique id to each of the bad ninja instances?

It sounds like it might have the following logic:

- If (any)Ninja sprite hits player with invisible star, then throw star

Instead of:

- If Ninja1 sprite hits... (only)Ninja1 shoots
B
5
S
1
Posts: 14
Reputation: 754

Post » Sun Nov 04, 2012 10:26 pm

I'm not sure how I go about that if there are an indeterminate number of baddies...? There's something I'm just not getting about the whole instance thing I guess. Here's a screen grab of the bad ninja logic:


B
5
Posts: 11
Reputation: 722

Post » Mon Nov 05, 2012 2:34 am

Hey Whaleboy,

There is a lot of different ways you could get your project working. It's a shame you cant link a capx (Dropbox is a good thing for this, but Im not sure if they allow new users to host anymore).

Anyway, it all works until they go to throw a ninja star (So you have narrowed it down to event 12). In certain games you might actually want all the baddies to shoot when one spots the hero, you just need to be more specific with your conditions so that only 1 baddy is picked.

At the moment event 12 reads as:

When a raycast hits the ninja -> Baddy object throw ninja star.

What is the link between the individual raycasts and the baddies? How do we know that this raycast is thrown by that baddy? We dont, and this is the problem. Remember unless your specifically targeting 1 'instance' of an object you will target all of them.

At this point again there is no wrong answer to how you will do this, just choices. If you only have four ways of movement - what I would do is attach some bar objects to the baddies that signify there range (its the the same concept as the invisible camera object - if your not familiar, the only difference is that we want the bars to all start from the base of the baddy).

This way when the hero overlaps one of these range objects you can easily target the right baddy to throw the ninja star. Below is meant to be a single event with two conditions in it.

Eg.) Ninja is overlapping Enemy range
     Baddy is overlapping Enemy range -> throw as in other event


You could have any number of baddies this way (with 4 times as many instances of the 'Enemy range' tiled-background object). The above event will only throw a ninja star when both the Baddy and Ninja is overlapping the same Enemy range object.

Wow massive rant - I hope others can learn from this as well! :)GenkiGenga2012-11-05 02:53:47
ImageImage
B
73
S
16
G
6
Posts: 1,039
Reputation: 10,480

Post » Mon Nov 05, 2012 3:41 pm

Thanks for the reply, I'm not at my proper pc at the moment so can't have a go at trying your suggestion at the moment, but I'll try and post my capx again:

docs.google.com/open?id=0BwoaeBCiAbv0VldINXpWVnBJY0U

Hopefully that will work now!
B
5
Posts: 11
Reputation: 722

Post » Mon Nov 05, 2012 7:35 pm

Ok, I've given it another go, but I just can't get it to work correctly. I did as you said and attached a range object to the baddies (I used a cone, but thinking about it a bar as you suggested is probably sufficient). Now the baddies only fire out a raycast if the player is in his range object. So far so good. But the trouble starts when the player is in 2 baddies range objects. They both fire out a raycast as expected, but even if only one of the baddies raycast objects hits the player they BOTH fire out a ninja star! Grrrrr. I can't seem to figure out how to associate the raycast objects to the badies that are spawing them. Here's the new logic:



and here's the capx file on google docs:
docs.google.com/open?id=0BwoaeBCiAbv0VVlqbzM4Q0tmbFk
B
5
Posts: 11
Reputation: 722

Post » Mon Nov 05, 2012 10:46 pm

In the part where you have Raycast -> on collision with ninja (event 11)
That's going to trigger all baddies to spawn and throw a ninja star. you need to create a subevent that picks only the instance that was filtered by the raycast, so that only one the specific ninja throws it.

ill check out the capx when i get home
B
50
S
21
G
8
Posts: 844
Reputation: 10,299

Post » Mon Nov 05, 2012 11:31 pm

I would put an instance variable on the Raycast named "Owner" then when you spawn the Raycast at the Baddy location, set "Owner" to the UID of the baddy.
Then on Raycast colliding with the ninja, "Pick by UID" on the baddys and put that owner variable in that picking. That way only the baddy that spawned the Raycast will exist to whatever you do in that event.
B
200
S
51
G
30
Posts: 897
Reputation: 36,496

Post » Tue Nov 06, 2012 2:29 am

Hey Whaleboy,

The whole thing with the range object is that it is acting as your raycast - all of the time. When the player touches the range object its the same as being hit by the raycast. I see after checking it out though that this might not be the best solution for your project.

Still, here is an example of what I suggested for learning puposes : Update I accidently overwrit this when I changed it for the next one (no learning today lol).

When you said four-way movement I was envisioning a bomberman style layout (where the enemies needs to be on your line to hit you), but since the enemies can target you from any angle it changes things a bit.

What Paradox suggested is better in your case, its still easy too. I have a bit of work to do now but If someone hasnt posted a fix I will come back and do it for you when I get some free time.GenkiGenga2012-11-06 04:26:10
ImageImage
B
73
S
16
G
6
Posts: 1,039
Reputation: 10,480

Post » Tue Nov 06, 2012 4:11 am

I know what I said, but I cant concentrate properly until this is resolved (bit of an OCD thing perhaps! lol)

Check this out, given how your game layout works I think you will like it. Props to Rexu because it is adapted from a great example he put out a while ago about line of sight.

http://db.tt/UMER0sU0GenkiGenga2012-11-06 04:11:52
ImageImage
B
73
S
16
G
6
Posts: 1,039
Reputation: 10,480

Next

Return to How do I....?

Who is online

Users browsing this forum: luckyrawatlucky, mindragon73 and 28 guests