Trouble with object instances

0 favourites
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • 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! <img src="smileys/smiley19.gif" border="0" align="middle" />

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

    Thanks! :)

  • 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
  • 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:

    <img src="http://i.imgur.com/e4IwG.jpg" border="0" />

  • 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! :)

  • 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!

  • 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:

    <img src="http://i.imgur.com/8OawV.jpg" border="0" />

    and here's the capx file on google docs:

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

  • 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

  • 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.

  • 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.

  • 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.

    db.tt/UMER0sU0

  • Thanks for all the help guys! Ok, I see now I was doing it all kinds of wrong. I added the line of sight stuff you posted GenkiGenga, and I'm also trying to use UIDs to filter objects. I'm still getting a problem with 2 enemies firing at the player even if only one of them is in range. I know its something to do with checking the UID but I'm not sure how to proceed. Here's the latest capx...

    docs.google.com/open

  • Arg! Another issue I'm having is that when I pin newly spawned line-of-sight objects to enemies that are not created at runtime (they are just placed in the layout view) it ends up pinning all the line-of-sight objects to a single enemy..!

    Here's how I'm pinning them:

    <img src="http://i.imgur.com/Lsv3i.jpg" border="0" />

    Any ideas?

    edit: oh and here's the capx <img src="smileys/smiley1.gif" border="0" align="middle" />

    docs.google.com/open

  • I never used the line of site tutorial, (yet) so someone who has used it may sort out some of the problems with that.

    But just a quick look changing event 3 to be "For Each" enemy (under system) seemed to fix the lines connecting to the right ememy...

    Edit: Oh, just noticed I could shoot, shot one and saw it left the line of site sprite.

    Add an event so if a line isn't pinned destroy it. Like event 5 in the image.

    <img src="https://dl.dropbox.com/u/85412219/forumposts/ninja.png" border="0" />

    Ok, looking a little more, I think I see one conflict, event 12, (13 if you aready added the destroy line event above.)

    12. IF player is overlapping a Line, AND any of those lines are not on a wall.

    It is possible for the player to be overlapping more than one line, and only one has to be clear of the wall.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Looks like in Event 4 the length of all the lines is set by the distance between the player and the enemy with the lowest ID. (in other words neither are picked.)

    it needs a "for each" there as well, but that is where you need to have an ID to tell which line belongs to which enemy. This is where the knowledge of the Line of site routine would help.

    Edit: Nevermind, it hit me how the routine must work, instead of the distance between the enemy and the player, just use the Line_of_Sight.x and Y instead. (line 4 change "Enemy.x" to "Line_of_Sight.x" & "Enemy.y" to "Line_of_Sight.y"

    that fixes it. However the lines seem to be offset like the origin point is at the top left. Ah, just checked, the origin point is right in frame one, but jumps all over the place on other frames and animations.

    Well, I have it, I may as well save you the typing now:

    https://dl.dropbox.com/u/85412219/forumposts/ninjaproject.capx

    however even with the origins all centered, it still seems to draw the lines offset.

  • Thanks for that! Its a definite improvement. Getting my head around how this all works is proving more difficult than I first thought. Glad to know there are people around who are so good at answering questions :)

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