Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
hyperPad

hyperPad Forum

  1. Home
  2. Help and Support
  3. Homing projectile vs multiple targets

Homing projectile vs multiple targets

Scheduled Pinned Locked Moved Help and Support
59 Posts 5 Posters 29.5k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SplitMindGamingS SplitMindGaming

    @Aidan-Oxley I see. Im still confused on the box container titled “minimum distance”. It says there’s no value being stored. So how is it calculating the minimum distance? Sorry it might be really obvious to you but I can’t seem to wrap my head around what is going on here.4E1BAE75-2A9B-48C3-8D49-62B958FECFB6.jpeg

    Jack de WildeJ Offline
    Jack de WildeJ Offline
    Jack de Wilde
    wrote on last edited by Jack8680
    #46

    @SplitMindGaming The value is set by the Set Input Field5 behaviour

    If calculate distance is less than minimum distance, set minimum distance to calculate distance.

    SplitMindGamingS 1 Reply Last reply
    1
    • Jack de WildeJ Jack de Wilde

      @SplitMindGaming The value is set by the Set Input Field5 behaviour

      If calculate distance is less than minimum distance, set minimum distance to calculate distance.

      SplitMindGamingS Offline
      SplitMindGamingS Offline
      SplitMindGaming
      wrote on last edited by
      #47

      @Jack8680 ohhh ok that’s where that input field came from. I got distracted from the other input field that had an “a” on it

      SplitMindGamingS 1 Reply Last reply
      1
      • SplitMindGamingS SplitMindGaming

        @Jack8680 ohhh ok that’s where that input field came from. I got distracted from the other input field that had an “a” on it

        SplitMindGamingS Offline
        SplitMindGamingS Offline
        SplitMindGaming
        wrote on last edited by
        #48

        Ok one last question. Sorry Bosswave I know this is your post and I’m kind of taking over it lol. So on the if statement you put if loop Index is = to 0. 0 represents the first item on the list of loops correct. So if I put a 1. What will happen?

        SplitMindGamingS Aidan_FireA 2 Replies Last reply
        0
        • SplitMindGamingS SplitMindGaming

          Ok one last question. Sorry Bosswave I know this is your post and I’m kind of taking over it lol. So on the if statement you put if loop Index is = to 0. 0 represents the first item on the list of loops correct. So if I put a 1. What will happen?

          SplitMindGamingS Offline
          SplitMindGamingS Offline
          SplitMindGaming
          wrote on last edited by
          #49

          Actually the more I look at it the more I get confused. I’m not understanding how this small piece of logic is doing all these things. Ok so in idiot terms. Minimum distance is a set input field. On that set input field you place the “calculate distance” ok makes sense. But on the other if statement it has if calculate distance is less the minimum distance. But aren’t you putting the calculate distance within the minimum distance because your using the input field to capture the calculate distance. So in reality the if statement is reading the same thing basically which is “ if calculate distance equals calculate distance right. I think I have a migraine now.

          1 Reply Last reply
          0
          • SplitMindGamingS SplitMindGaming

            Ok one last question. Sorry Bosswave I know this is your post and I’m kind of taking over it lol. So on the if statement you put if loop Index is = to 0. 0 represents the first item on the list of loops correct. So if I put a 1. What will happen?

            Aidan_FireA Offline
            Aidan_FireA Offline
            Aidan_Fire
            wrote on last edited by
            #50

            @SplitMindGaming If you put 1 in the If statement that is looking at the loop index, then it will apply the logic to the second object it looks at. I think the order of the loop goes from oldest spawned object up to newest. If I'm right about this, then setting it to 1 will mean the oldest spawned target will always be completely ignored by the homing missiles.

            SplitMindGamingS 1 Reply Last reply
            0
            • Aidan_FireA Aidan_Fire

              @SplitMindGaming If you put 1 in the If statement that is looking at the loop index, then it will apply the logic to the second object it looks at. I think the order of the loop goes from oldest spawned object up to newest. If I'm right about this, then setting it to 1 will mean the oldest spawned target will always be completely ignored by the homing missiles.

              SplitMindGamingS Offline
              SplitMindGamingS Offline
              SplitMindGaming
              wrote on last edited by SplitMindGaming
              #51

              @Aidan-Oxley lol you don’t need to answer my last question. Honestly I still won’t probably get it. You would have to really dumb it down for me by using apples and bananas as a metaphors at this point because that was all too confusing for me.

              1 Reply Last reply
              0
              • Aidan_FireA Offline
                Aidan_FireA Offline
                Aidan_Fire
                wrote on last edited by Aidan_Fire
                #52

                Let me try to give you an example, for example there are 3 targets in the world. Let's call them object a b and c, where a is the oldest one and c is the youngest one (the last one spawned). Object a is a medium distance away, it's sitting 5m away from the missile. Object c is 7m away from the missile, and object b is right next to the missile being 2m away. Now the objects are in these places, let's say the homing logic is triggered right now, with the objects in these places:

                The loop has target as its tag, and it sees 3 targets (hyperPad does this automatically), so the loop is going to trigger all the behaviours underneath it 3 times. The first time is run, and the loop index is now 0. It calculates the distance to object a (the oldest) first, and gets 5. Then it runs the If statement, is index equal to 0? Yes. So now set the Minimum Distance box container to 5. After this is done, it runs the 2nd If statement. Is the calculate distance LESS THAN or EQUAL TO the minimum distance? 5 = 5, so yes. Get the ID of the object we just calculated distance to (which is object a). First loop done.

                Second loop, now the index is 1, and it is now looking at object b. Calculate distance, and it gets a value of 2. Does index = 0? No, so the first If statement does nothing. Second If statement, is the calculate distance less than or equal to the minimum distance? The minimum distance is currently still 5 at this point, and 2 is less than 5. So now we set the minimum distance to the calculated distance (which is 2 right now), and get the ID of this object (which is the ID of object b).

                3rd and last loop, the index is 2 and looking at object c. Calculate distance, gets 7. Index = 0? Nope, it's 2, do nothing under this If statement. Is calculate distance ≤ minimum distance? 7 is not less than or equal to 2, so do nothing.

                The loop is done, now continue on. The homing timer is set to home in on the last object that had it's ID taken, and this is object B, so the missile will now home in on object B, which was the closest one being 2m away.

                SplitMindGamingS 2 Replies Last reply
                1
                • Aidan_FireA Aidan_Fire

                  Let me try to give you an example, for example there are 3 targets in the world. Let's call them object a b and c, where a is the oldest one and c is the youngest one (the last one spawned). Object a is a medium distance away, it's sitting 5m away from the missile. Object c is 7m away from the missile, and object b is right next to the missile being 2m away. Now the objects are in these places, let's say the homing logic is triggered right now, with the objects in these places:

                  The loop has target as its tag, and it sees 3 targets (hyperPad does this automatically), so the loop is going to trigger all the behaviours underneath it 3 times. The first time is run, and the loop index is now 0. It calculates the distance to object a (the oldest) first, and gets 5. Then it runs the If statement, is index equal to 0? Yes. So now set the Minimum Distance box container to 5. After this is done, it runs the 2nd If statement. Is the calculate distance LESS THAN or EQUAL TO the minimum distance? 5 = 5, so yes. Get the ID of the object we just calculated distance to (which is object a). First loop done.

                  Second loop, now the index is 1, and it is now looking at object b. Calculate distance, and it gets a value of 2. Does index = 0? No, so the first If statement does nothing. Second If statement, is the calculate distance less than or equal to the minimum distance? The minimum distance is currently still 5 at this point, and 2 is less than 5. So now we set the minimum distance to the calculated distance (which is 2 right now), and get the ID of this object (which is the ID of object b).

                  3rd and last loop, the index is 2 and looking at object c. Calculate distance, gets 7. Index = 0? Nope, it's 2, do nothing under this If statement. Is calculate distance ≤ minimum distance? 7 is not less than or equal to 2, so do nothing.

                  The loop is done, now continue on. The homing timer is set to home in on the last object that had it's ID taken, and this is object B, so the missile will now home in on object B, which was the closest one being 2m away.

                  SplitMindGamingS Offline
                  SplitMindGamingS Offline
                  SplitMindGaming
                  wrote on last edited by
                  #53

                  @Aidan-Oxley that was perfect actually. Everything makes a lot more sense now. Thanks for that.

                  1 Reply Last reply
                  0
                  • Aidan_FireA Aidan_Fire

                    Let me try to give you an example, for example there are 3 targets in the world. Let's call them object a b and c, where a is the oldest one and c is the youngest one (the last one spawned). Object a is a medium distance away, it's sitting 5m away from the missile. Object c is 7m away from the missile, and object b is right next to the missile being 2m away. Now the objects are in these places, let's say the homing logic is triggered right now, with the objects in these places:

                    The loop has target as its tag, and it sees 3 targets (hyperPad does this automatically), so the loop is going to trigger all the behaviours underneath it 3 times. The first time is run, and the loop index is now 0. It calculates the distance to object a (the oldest) first, and gets 5. Then it runs the If statement, is index equal to 0? Yes. So now set the Minimum Distance box container to 5. After this is done, it runs the 2nd If statement. Is the calculate distance LESS THAN or EQUAL TO the minimum distance? 5 = 5, so yes. Get the ID of the object we just calculated distance to (which is object a). First loop done.

                    Second loop, now the index is 1, and it is now looking at object b. Calculate distance, and it gets a value of 2. Does index = 0? No, so the first If statement does nothing. Second If statement, is the calculate distance less than or equal to the minimum distance? The minimum distance is currently still 5 at this point, and 2 is less than 5. So now we set the minimum distance to the calculated distance (which is 2 right now), and get the ID of this object (which is the ID of object b).

                    3rd and last loop, the index is 2 and looking at object c. Calculate distance, gets 7. Index = 0? Nope, it's 2, do nothing under this If statement. Is calculate distance ≤ minimum distance? 7 is not less than or equal to 2, so do nothing.

                    The loop is done, now continue on. The homing timer is set to home in on the last object that had it's ID taken, and this is object B, so the missile will now home in on object B, which was the closest one being 2m away.

                    SplitMindGamingS Offline
                    SplitMindGamingS Offline
                    SplitMindGaming
                    wrote on last edited by
                    #54

                    @Aidan-Oxley you also mentioned that loops work really fast and lag the game. Does this mean that we should try to avoid loops as much as possible?

                    Jack de WildeJ 1 Reply Last reply
                    0
                    • SplitMindGamingS SplitMindGaming

                      @Aidan-Oxley you also mentioned that loops work really fast and lag the game. Does this mean that we should try to avoid loops as much as possible?

                      Jack de WildeJ Offline
                      Jack de WildeJ Offline
                      Jack de Wilde
                      wrote on last edited by Jack8680
                      #55

                      @SplitMindGaming well a loop basically runs the behaviours under it multiple times at once. Imagine you have a loop with 5 behaviours under it, and that loop runs 5 times, it actually runs 5x5=25 behaviours.

                      It'd be a lot more complicated (and not perfect), but if you have loads of potential targets to the extent that the targeting causes the game to lag, you could try splitting the search for nearest over multiple frames by creating an array of objects to search through and only searching through (e.g.) 50 each frame.

                      Depending on the type of game, you could also just make it so it doesn't switch targets after selecting one (only running the search once).

                      SplitMindGamingS 1 Reply Last reply
                      1
                      • Jack de WildeJ Jack de Wilde

                        @SplitMindGaming well a loop basically runs the behaviours under it multiple times at once. Imagine you have a loop with 5 behaviours under it, and that loop runs 5 times, it actually runs 5x5=25 behaviours.

                        It'd be a lot more complicated (and not perfect), but if you have loads of potential targets to the extent that the targeting causes the game to lag, you could try splitting the search for nearest over multiple frames by creating an array of objects to search through and only searching through (e.g.) 50 each frame.

                        Depending on the type of game, you could also just make it so it doesn't switch targets after selecting one (only running the search once).

                        SplitMindGamingS Offline
                        SplitMindGamingS Offline
                        SplitMindGaming
                        wrote on last edited by
                        #56

                        @Jack8680 ahh i see. Thanks guys I learned alot today.

                        1 Reply Last reply
                        0
                        • HamedH Offline
                          HamedH Offline
                          Hamed
                          Admin
                          wrote on last edited by
                          #57

                          You guys are literally teaching / learning university level computer science topics. So exciting to see 😭

                          1 Reply Last reply
                          0
                          • Aidan_FireA Aidan_Fire

                            @bosswave I made an example here:
                            https://go.aws/3eSSUsO
                            Press the red octagon to spawn missiles, press the blue one to spawn targets. Targets can be dragged around to test missiles. These homing missiles will calculate distances once and continue to home in on the same target (rather than constantly switching to whatever is closest). The homing trigger behaviour bundle is made in a way that it can be triggered at any time to cause the missile to choose a new closest target (or the same one as before if it's still close) but I would not recommend triggering this on a fast timer if you have lots of targets.

                            It took me a while to get it right because there were a few minor bugs I had to work around that I might try to figure out more details for to submit bug reports soon. (Just saying this in case you see the logic and see a more efficient way to do it, you might run into the exact same bugs I did)

                            Also they use very simple homing mechanics obviously you can easily change them if you have your own fancy cool looking homing missile physics, just have to use the same referenced object.

                            EDIT: this example sucks. This one is way better: https://go.aws/2zEM8XH

                            HamedH Offline
                            HamedH Offline
                            Hamed
                            Admin
                            wrote on last edited by
                            #58

                            @Aidan-Oxley said in Homing projectile vs multiple targets:

                            @bosswave I made an example here:
                            https://go.aws/3eSSUsO
                            Press the red octagon to spawn missiles, press the blue one to spawn targets. Targets can be dragged around to test missiles. These homing missiles will calculate distances once and continue to home in on the same target (rather than constantly switching to whatever is closest). The homing trigger behaviour bundle is made in a way that it can be triggered at any time to cause the missile to choose a new closest target (or the same one as before if it's still close) but I would not recommend triggering this on a fast timer if you have lots of targets.

                            It took me a while to get it right because there were a few minor bugs I had to work around that I might try to figure out more details for to submit bug reports soon. (Just saying this in case you see the logic and see a more efficient way to do it, you might run into the exact same bugs I did)

                            Also they use very simple homing mechanics obviously you can easily change them if you have your own fancy cool looking homing missile physics, just have to use the same referenced object.

                            EDIT: this example sucks. This one is way better: https://go.aws/2zEM8XH

                            @Aidan-Oxley what were the bugs?

                            Aidan_FireA 1 Reply Last reply
                            0
                            • HamedH Hamed

                              @Aidan-Oxley said in Homing projectile vs multiple targets:

                              @bosswave I made an example here:
                              https://go.aws/3eSSUsO
                              Press the red octagon to spawn missiles, press the blue one to spawn targets. Targets can be dragged around to test missiles. These homing missiles will calculate distances once and continue to home in on the same target (rather than constantly switching to whatever is closest). The homing trigger behaviour bundle is made in a way that it can be triggered at any time to cause the missile to choose a new closest target (or the same one as before if it's still close) but I would not recommend triggering this on a fast timer if you have lots of targets.

                              It took me a while to get it right because there were a few minor bugs I had to work around that I might try to figure out more details for to submit bug reports soon. (Just saying this in case you see the logic and see a more efficient way to do it, you might run into the exact same bugs I did)

                              Also they use very simple homing mechanics obviously you can easily change them if you have your own fancy cool looking homing missile physics, just have to use the same referenced object.

                              EDIT: this example sucks. This one is way better: https://go.aws/2zEM8XH

                              @Aidan-Oxley what were the bugs?

                              Aidan_FireA Offline
                              Aidan_FireA Offline
                              Aidan_Fire
                              wrote on last edited by Aidan_Fire
                              #59

                              @Hamed Oh right I forgot about them. Uh, I'll go try remember and make proper bug reports. I think there was actually only 1 bug.

                              1 Reply Last reply
                              0

                              Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                              Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                              With your input, this post could be even better 💗

                              Register Login
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              • Login

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Search