Skip to main content

Search

AI choose the closest target

  • Supposer

    I haven't tried this myself, but I've seen others talk about it...

    Use a follower with everything zeroed. Set it to look for the target tag name. It will only actually find the closest one, I believe. Then use the target position output of the follower to know where that is.

    Hope this helps.

  • AndymationB

    I considered something similar to that, but for other conditional logic, it's necessary for me to know which target has been chosen. I appreciate the help though. It may be that there isn't a more elegant way of handling this. :-/

  • oLMCo

    If you put one Laser Scope on the Hunter instead and set it to 'Look at Tag' then tag all the targets I'm pretty sure it will automatically aim at the closest one. Then you could take any useful data directly from the hunter, hit position/distance etc.

  • AndymationB

    Yeah, Laser Scopes are probably cheaper than a follower with zero strength. But as I was saying, I need the hunter to know which target (1, 2, 3, 4, or 5) it's chasing in order to adapt other behaviors. Logic isn't my strong suit, so I figured I must be over complicating it, but maybe not. Maybe this is just going to be a bit complicated no matter what. lol

    I appreciate the suggestion!

  • Mm Bogdan & Matt

    Hi, an extension of Supposer's idea would be for each of your targets to broadcast their position. I.e. for each target, add a tag, wire the tag "Scene Space Transform" into a splitter. Wire the position output from the splitter into a wireless transmitter named differently for each target ("Target 1 position", "Target 2 Position" etc.).

    Then on the hunter you can subtract the "target position" output from each of the transmitted positions using a calculator. Then use another calculator to compare each result against zero (or close to zero). The one that is being targeted should return true.
    Not very elegant, but should work!
    thanks
    Matt

  • AndymationB

    OooooOOOooh...

    Winner winner, chicken dinner! Looking forward to trying that out tonight. It certainly sounds like it will be more efficient than my current tangle of calculators.

    Thanks, Matt!

  • oLMCo

    Oh okay, you want information back about the target. I thought you just wanted to be able to track the closest one.

    I think there are a number of issues with Supposers/Matts idea but I wont go into it because it's complicated, try it and see if you have any luck though.

    If you don't have any luck I've tested it and come up with 2 ways.

    First way:
    Answering what you initially asked about keeping track of where the signal came from once you've processed it to determine the shortest distance.
    Keeping it the way you have it with the Laser Scopes on the targets. The circuit in the attached image will compare the signals coming in and turn on an output corresponding to the lowest one. If you don't mind more then one being on at a time (2 or more targets are same distance away) you can ignore the selector and just use the = Calculators directly.

    Seconds way:
    Do as I said with a single Laser Scope on the hunter. Take the Hit Position from that and input it into a Followers Target Position on a separate object. Put a Trigger Zone on that following object and use that to detect the target and set off its Detected output. Then you can use that to let the hunter know whether a target is targeted or not.

    I'm not sure what way is more elegant. First way has no separate moving parts, second uses less gadgets.

  • AndymationB

    Very interesting! I think I see where you're going with that. You're right, it could be a lot fewer gadgets. All the suggestions are greatly appreciated. It's nice to have options to try out in case I can't get one way working quite right.

    Thanks guys!

  • CLOUD1985

    A simple workaround (with very minimal logic) since you only want 5 targets would be as oLMCo said in tag each target and laser scope the hunter (it will point at the closest one)

    Then assign each target a different label. Make the laser scope detect the labels and when it hits a target the laser scope sets a logic high signal on that label, telling you which one it's pointing at.

  • oLMCo

    '@ CLOUD1985
    Where does the signal from a specific label come from? the label output? (Friend, Foe etc.)
    If so I never knew that thanks! I tried to get it working like that a while ago with no luck, would be really handy.

    That would be the best way for sure yeah, if I'm understanding you right? (getting individual signals for multiple labels from a single gadget)

  • AndymationB

    I'm also not sure how to get the label ID out of the scope. Please let us know, because if there is a way, that would clearly be the most convenient method.

  • oLMCo

    Hey Andy, I was playing around with the laser scope and couldn't find what I thought CLOUD meant.

    I think they actually meant using 5 scopes on the hunter not 1, and each set to a different label. I ended up trying that and it works greats. Make them all follow the same tag on the targets and they all will point at the closest one but only the scope with the matching label will activate.

    Cant get any more elegant then that if you don't mind using up 5 labels. Great job CLOUD! Didn't quite follow you at first, its the perfect solution.

  • AndymationB

    Ah, that makes more sense. Thanks again guys. That's one logic problem down.

    Only about another umpteen left to go. lol. This is my most ambitious logic setup in a scene that I've done yet, and I'm grappling with how hard it is to track down problems when there's so many places to check. If I can't get this figured out over the weekend, I think I'm going to stick to art and puppets for a while. :P

  • oLMCo

    I found a problem with using just the 5 scopes. Because they are all set off by different labels they can look through the target they are aiming at and hit one behind. So sadly that wont work consistently.

    That gave me an idea though, do a hybrid of the 2. Put 5 scopes on the hunter still but make them each follow a different target tag. Use different labels too so only the correct target will set off the scope. Then put it through that comparing hit distance logic to determine the closest. This way you dont need to use any transmitters/receivers and all the logic is in one place on the hunter, only need a tag on the targets.

    Even though it uses more logic then the follower/trigger zone method, testing it it is a lot less fiddly and works flawlessly every time so I think thats better then having something flying around the place.
    Also in that circuit I showed you, replace the selector with 5 exclusive gates. The selector seems to only change ports when a signal first goes on. Exclusive gates seem to work much better anyway, if 2 or more signals come in they will always stick with the first one it revives. So it will keep the current target rather then changing if they are the same distance.
    Also you can priorities them if you like, say 2 targets are the same distance it would favour one over another. Could dynamically change that too like it could target the once with the most health or the slower one etc.

    I've tested all this and seems to work perfectly. If you want me to publish it so you dont have to remake or even just want to take a look let me know.

  • AndymationB

    Thanks. To be honest, the scene's logic is a bit of hot mess at the moment.
    my original set up was mostly finished, so I was trying to save myself some work by just going with that, but the scopes seemed to be giving inconsistent feedback if anything else was in their path. Even with Xray mode on.

    But this is my first foray into this kind of logic, so I'm assuming it's some kind of user error. Should I just be using the distance output on the third tab? That's how I have it right now.

    Would puppet scale affect the output? I noticed last night that the smallest puppet (i.e. target) seemed to get chosen constantly, even when it was furthest away. I don't know if the two things are correlated or coincidental.

    I'll take a look at whatever you sent when I get home tonight. I'm actually not adverse to having targets switch if one moves blatantly closer, but it's probably best to have some kind of delay at least built in, that way the pursuit isn't ground to a halt by indecision. lol

    Thanks again, you've really been going above and beyond testing these things out for me.

  • oLMCo

    You need to label the scope/target so the scope can only hit the hunter (assuming you have the original set up, scopes on targets). Label the hunter foe or something and all the scopes the same. Will fix it hitting things other then the hunter.

    Yeah if you are doing the comparing distance thing youre using the right one, Hit Distance or something I think its a ruler.

    If you scaled your puppet after you put the scope on it then yes that would affect the length setting, itll stay the same size relative to the puppet. You can go back and increase it in the tweak menu though.

    I havent sent anything yet, didnt want to publish in case you didnt want/need it as you cant delete stuff. I will now though.
    Shouldn't have to redo a lot, it is quite self contained and modular. Thats why I like that solution even though it uses a few calculators.

    And no worries, I actually really like logic and problem solving. I have the opposite problem to you, I have a fully functioning level with some quite involved logic and game play systems all done but need to do all the visual stuff now like sculpting character etc. Don't find that as fun more frustrating. With logic its like a journey of things working progressively better but with art it either works or it doesnt lol.

    If you ever want help with logic or stuff like that let me know, am normally pretty good with it. You seem good at picking up concepts and learning things quickly so it is a pleasure to help.

  • CLOUD1985

    Sorry guys I should have been clearer in my post, you are correct and it requires a scope for each target label, so 5 label scopes on the hunter.

    I did not think about the scopes hitting objects behind the first target but this is very easily dealt with by using one more scope to determine the distance to the closest object and using this value (the hit distance output of this extra scope) to adjust the range of all the other label scopes.

    Set the extra scope to look at the same tag and see all 5 labels.

    You need to use two calculators to get the range value, one takes the hit distance output from the extra scope and adds a small value to it (eg 0.25) to allow the label scopes to track the target when it is in motion. You then take this value and multiply it by 10 (centimeters to meters conversion) before plugging it into the range input of the label scopes.

    Now when the extra scope hits one of the labels, it will adjust the range value on the label scopes and the label scopes will end somewhere just inside the object they are hitting.

    Now label scopes cannot see targets behind the closest target.

  • oLMCo

    Oh yeah, nice one CLOUD once again good idea.

    I thought about ways of changing the distance with an existing scope but it would default to 0, didn't think of using another scope.

    I tried it out and it works. If you set the input to modulate and the distance to 1 you dont need the second calculator. You could set it to a little over 1 and not need any calculators, but the over shoot would change relative to the distance so I think its best to use 1 calculate to add a set amount to the distance. (doesnt seem to work if you just use the hit distance and dont at a bit to it)


    There you go Andy, think that is the best solution again.

    Oh yeah by the way, if you want to save your self a label you can use 4 labels in pairs to form a code. eg
    1. Friend+Foe
    2. Friend+Scenery
    3. Friend+Object
    4. Foe+Scenery
    5. Foe+Object
    +6. Scenery+Object if you needed it.

    Thats what I done, set the the scope match mode to 'All Selected'

  • AndymationB

    The scene as a whole is still a work in progress, but this part is functioning beautifully.

    I did run into some problems where a bunch of puppets had been scaled to different degrees, so copy and pasting the logic required some trial and error to dial in the multiplier for the scope range, but it's working! Hurrah!

    Thank you all very much!

  • CLOUD1985

    Great stuff Andy, glad I could help. Look forward to seeing the finished level

Please sign in to leave a comment.