hyperPad hyperPad Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Login

    Homing projectile vs multiple targets

    Scheduled Pinned Locked Moved
    Help and Support
    5
    59
    4.1k
    Loading More Posts
    • 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.
    • Aidan_FireA
      Aidan_Fire @SplitMindGaming
      last edited by

      @SplitMindGaming Doesn't matter. When the missile spawns or the homing logic is triggered, it will look at all objects that currently exist with the tag "target".

      Jack8680J 1 Reply Last reply Reply Quote 0
      • Jack8680J
        Jack8680 @Aidan_Fire
        last edited by

        @Aidan-Oxley We think in different ways when making something like this lol.

        1 Reply Last reply Reply Quote 0
        • SplitMindGamingS
          SplitMindGaming @bosswave
          last edited by

          @bosswave here’s my ghetto way of doing it. It doesn’t use arrays. Very simple logic really. But this only works assuming you already spawned in your objects. You can always just already have the objects spawned in but hidden away far off screen. Then have certain events move that object to scene when you want it. You will notice that this method does work and it will follow the closest square that’s next to it. So go ahead move each square next to the missile and it will follow the closest one. Maybe this can be a temporary approach until you learn arrays and know the ways of master aiden. Use safari to download and open this project.Homing missile.tap

          Jack8680J 1 Reply Last reply Reply Quote 0
          • SplitMindGamingS
            SplitMindGaming
            last edited by

            Here’s a video showcasing it follow the closest squareFullSizeRender.mov

            1 Reply Last reply Reply Quote 0
            • Jack8680J
              Jack8680 @SplitMindGaming
              last edited by

              @SplitMindGaming I think Aidan's reworking his to not use arrays right now lol

              SplitMindGamingS 1 Reply Last reply Reply Quote 0
              • SplitMindGamingS
                SplitMindGaming @Jack8680
                last edited by

                @Jack8680 yeah he’s about to poop on mine right now just wait for it.

                Jack8680J 1 Reply Last reply Reply Quote 0
                • Aidan_FireA
                  Aidan_Fire @bosswave
                  last edited by Aidan_Fire

                  @bosswave Don't use the other example, use this one instead: https://go.aws/2zEM8XH
                  Jack made me realise what I was doing before is really over complicating the problem, this one is way simpler and doesn't even use arrays.

                  It's so funny how you can make something complicated, but then it ends up being dumb because of how simple it can actually be.

                  SplitMindGamingS 1 Reply Last reply Reply Quote 1
                  • Jack8680J
                    Jack8680 @SplitMindGaming
                    last edited by Jack8680

                    @SplitMindGaming Haven't looked at yours yet, but I think the best way is something like this:

                    minDistance = -1;
                    foreach(potentialTarget in tag)
                    {
                        distance = CalculateDistance(self, potentialTarget );
                        if(minDistance == -1 OR  distance < minDistance)
                        {
                            minDistance = distance;
                            target = potentialTarget;
                        }
                    }
                    

                    Or if there's a maximum range, you can just do

                    minDistance = maxRange;
                    foreach(potentialTarget in tag)
                    {
                        distance = CalculateDistance(self, potentialTarget );
                        if(distance < minDistance)
                        {
                            minDistance = distance;
                            target = potentialTarget ;
                        }
                    }
                    

                    Too bad having an OR in hyperPad isn't quite the same as in a normal programming language; if you put two ifs next to each other connected to the same group of behaviours, it's possible for them to both be true and run the behaviours underneath twice, so it gets a bit messy.

                    1 Reply Last reply Reply Quote 1
                    • SplitMindGamingS
                      SplitMindGaming @Aidan_Fire
                      last edited by

                      @Aidan-Oxley the thing I notice with yours is that it doesn’t follow the closest square. It only follows and locks on 1 target. It doesn’t redirect. Did u check out my video on how mine behaves?

                      Aidan_FireA 1 Reply Last reply Reply Quote 0
                      • Aidan_FireA
                        Aidan_Fire @SplitMindGaming
                        last edited by Aidan_Fire

                        @SplitMindGaming It finds the nearest target ONCE, and chases that one forever. It can be told to redirect whenever you want, just activate the behaviour bundle called "Homing trigger" and it will redirect to the nearest target and then chase that one forever. For example: edit the project and add a timer and connect Homing trigger (with all the behaviours under it) underneath the timer. Don't make the timer too fast or you could lag/freeze the project if you have spawned in lots of targets. 0.5s would be fine.

                        I did look at yours. I moved the blue and green squares both to the top right of the screen and the missile just stopped and sat there.

                        SplitMindGamingS 2 Replies Last reply Reply Quote 0
                        • SplitMindGamingS
                          SplitMindGaming @Aidan_Fire
                          last edited by

                          @Aidan-Oxley yeah I was going to say the same thing. When your missile hits the edge of the screen it just stops there and freezes.

                          1 Reply Last reply Reply Quote 0
                          • SplitMindGamingS
                            SplitMindGaming @Aidan_Fire
                            last edited by

                            @Aidan-Oxley 8AEC4F6A-BC05-4262-864B-D400B6E2A4AD.png

                            Aidan_FireA 1 Reply Last reply Reply Quote 0
                            • Aidan_FireA
                              Aidan_Fire @SplitMindGaming
                              last edited by Aidan_Fire

                              @SplitMindGaming If the object the missile is chasing gets deleted, the missile will stop and have nothing to do. In that case, you would want to add some logic to detect when its target is destroyed, and decide what to do then (e.g trigger homing again and select a new target, or just delete the missile). However if you get the missile to constantly redirect to the nearest target on a timer this shouldn't happen unless all targets are destroyed.

                              SplitMindGamingS 1 Reply Last reply Reply Quote 0
                              • SplitMindGamingS
                                SplitMindGaming @Aidan_Fire
                                last edited by

                                @Aidan-Oxley sorry I actually want this to work because it’s something I needed for my game as well. I attached a video of me playing your version and turned on the homing behavior as you said so that it can redirect. But it still doesn’t re direct. What am I doing wrong. Are you able to get urs to redirect? FullSizeRender.mov

                                SplitMindGamingS 1 Reply Last reply Reply Quote 0
                                • SplitMindGamingS
                                  SplitMindGaming @SplitMindGaming
                                  last edited by

                                  @SplitMindGaming never mind I activated the homing timer instead. How do you activate the behavior bundle homing trigger?

                                  Aidan_FireA 1 Reply Last reply Reply Quote 0
                                  • Aidan_FireA
                                    Aidan_Fire @SplitMindGaming
                                    last edited by

                                    @SplitMindGaming If you activate this behaviour in any way (by connecting it under another behaviour directly, using Behaviour On with it selected, or using Execute behaviour with it selected) the missile will redirect targets ONCE.
                                    0758C057-D03A-43DA-997E-693BDF364717.jpeg

                                    If I do this, the missile will redirect to the nearest target every 0.5s:97BAD3A6-97CF-4759-8AAF-6F265A0C6D63.png

                                    SplitMindGamingS 2 Replies Last reply Reply Quote 0
                                    • SplitMindGamingS
                                      SplitMindGaming @Aidan_Fire
                                      last edited by

                                      @Aidan-Oxley ahhh I didn’t add the timer. Yes it works flawlessly like that. Thanks

                                      1 Reply Last reply Reply Quote 0
                                      • SplitMindGamingS
                                        SplitMindGaming @Aidan_Fire
                                        last edited by SplitMindGaming

                                        @Aidan-Oxley care to be a teacher for a bit. I don’t understand input field or even how to use loop properly in that matter. What does it mean when you put “a” on the input field. What does that represent?

                                        Aidan_FireA 1 Reply Last reply Reply Quote 0
                                        • Aidan_FireA
                                          Aidan_Fire @SplitMindGaming
                                          last edited by Aidan_Fire

                                          @SplitMindGaming lol nothing. It's a mistake, I meant to put 0 or absolutely nothing in there. Now that I think about it, delete that behaviour completely, it'll still work exactly the same, it's leftover from my previous method before Jack showed me better one.

                                          Set Input Field basically does exactly as it says. When you press on that symbol next to the Input field of a behaviour, you are given a prompt and you can create a Set Input Field behaviour. When this behaviour is run, it simply changes whatever was in there to the new value you put in it.

                                          The loop behaviour is like a timer but extremely fast, as in it will freeze hyperPad until it is done (it won't freeze hyperPad unless you make it loop a crazy amount of times). It has a few settings, you can either set the exact amount of times you want it to repeat the stuf under it, or you can give it a tag and set it to "for each" where it will count the amount of objects in that tag by itself, and then repeat the stuff under it once for each object while also selecting that object to do stuff to.

                                          SplitMindGamingS 1 Reply Last reply Reply Quote 0
                                          • SplitMindGamingS
                                            SplitMindGaming @Aidan_Fire
                                            last edited by

                                            @Aidan-Oxley I see what about the box container minimum distance. It doesn’t even have any value storing. I notice it was called on an if statement saying if calculate distance is less then minimum distance. How does that calculate when the minimum distance contains no value. Or does it contain a value? I’m not sure exactly what happening there.

                                            Aidan_FireA 1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post