Homing projectile vs multiple targets



  • I’ve figured out how to simulate an effective homing projectile, but only when it has a single, specified target.

    I would like to find an efficient way for it to look at a group of spawned targets, calculate which is nearest, and follow that one. Is this at all possible? Thanks in advance!



  • @bosswave i havent tested it out but i would use

    Get position ( Missile )
    Get position ( object1)
    Get position (object 2)
    Get position (object 3)

    Then use if statements

    Not too sure how to chain it up but basically something like

    If get position missile is less then get position object 1, move missile to object 1. Else move to object 2 and so on. Something along the lines of that logic i beleive



  • @SplitMindGaming

    Thanks! But I’m not sure if this would work in my situation.

    I would like for it to calculate between objects that are spawned in on-the fly as opposed to pre-existing objects



  • @bosswave I made an example here:

    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 I swear your brilliant when it comes to those tricky codings. If my game gets big and I need a bigger team of developers. Just know your hired lol.



  • @Aidan-Oxley Thanks! I’ll definitely look into it and see if I can replicate your method lol.



  • @bosswave yeah good luck. I was already lost when he used arrays. In my mind I had a more ghetto approach but might have worked the same way I feel.



  • @Aidan-Oxley also I noticed something. How did you create those shapes from empty objects?



  • @SplitMindGaming if you change the collisions of an empty object, the shape matches the collision.



  • @SplitMindGaming I like seeing how different people have their strengths and weaknesses. I haven't seen your game yet, but from what you've said so far you seem to be good at the designing of games, but you struggle with the actual coding (which is why you want single behaviours that do a lot of things at once for you). I have the opposite, I like accepting challenges of making something most people don't know how to do, but I struggle with actually designing a game. By far most of my time spent in any of my projects is just making decisions.



  • @Aidan-Oxley I’ve never tried working with arrays before. Seems like I have my work cut out lol.

    And where the heck is the set input field behavior? Am I needing to purchase an upgrade to have access to it or something?



  • @Aidan-Oxley yes I thought the same thing. Both of us would actually compliment each other if we ever did decide to team up. It would be a force to be reckon with. Here’s a video of me showing a time lapse of something I did in photoshop a long time ago. Although doesn’t have to do with games but it kind of shows where my skills are at in terms of designing.



  • When missile spawns, it will run this loop that will repeat the logic under it once for every target object that exists, and it will do this very quickly (this completely freezes hyperPad if the loop tries to repeat too many times, that's how fast they are). In the loop, it will get the ID of a target object and calculate the distance to it. It will group the ID and calculated distance together in an array with the order of distance, ID. Then it will store this information in another array, and move on to the next target object, if there is one. Once it's finished the loop, it will sort the array from smallest calculated distance to largest, then all it needs to do is get the data from the start of the array (because it's the smallest), get the ID of the object with that distance and go home in on it.

    Don't know if this is helpful in understanding the logic, but there you go.



  • @bosswave Press here:816E405B-5DD1-4F6F-8801-72249AB86517.jpeg



  • @Aidan-Oxley Really all you need to do is loop through a list of targets and keep track of which one is closest, no? Rather than sorting the whole array.



  • @Jack8680 Yeah but that takes more behaviours :P need another box container to keep the minimum value, then get the minimum value every loop.

    EDIT: actually Jack's idea is more efficient and probably takes same amount of behaviours, and makes me wonder why I did it the way I did in the first place.



  • @bosswave you mentioned you want it to look at a group of spawned objects. Are these objects constantly spawning or do they spawn in once.



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



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



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


Log in to reply