Quantcast
Channel: Questions in topic: "javascipt"
Viewing all articles
Browse latest Browse all 1875

Need help in AI logic problem with multi target scenario!

$
0
0
Hi everyone there!! So i'm trying to make a fancy behaviour for my basic follow target AI. Well lets say that i'm trying to go forward with Ai behaviour development and still can't go beyond a basic follow & shoot AI. So i was trying to implement some kind of multi target method that allow the ai to face a multi target situation where there is more than just the player to shoot or attack at. And after a loot of efford for making this work. I came with a number of weird behaviours that i really have no idea how to fix or even approach. Well going into the core of this. One of my biggest throuble with this multi target situation for the ai to face. Is no more and no less than "CanSeeTarget?" This is a boolean function i found dont remember where exactly. And work pretty well with only one target situation. Here's the code : function CanSeeTarget ():boolean{ if (Vector3.Distance(transform.position, target.position) >attackRange) return false; var hit : RaycastHit; if (Physics.Linecast (EyePos.position, target.position,hit, SearchMask)){ lastVisibleTargetPosition = target.position; return hit.transform == target; } return false; } Sorry for the shit position of the lines of code but i can't fix it. Well as i was saying... This is i think the main problem of the weird behaviour my ai has. And of course i almost forgot to explain what is all about that weird behaviour. Well to be quick : Let's say that for example you have a 5v5 NPC/AI situation in a shooting scenario. So they get close by a simple path function that i set up so they can "behave" as a "moba" kind of battle. But as soon as they start fight each other start the weird stuff .Where they stop shooting and run forward to the enemy "battle side" and they start to get stuck in fron of and running against each other. Of course not all of the 10 npc do this, but pretty much like 6 or 7 do it while the others can behave "normal". I figure out that this is kind of "i can't see" situation. Where for some reason in a certain point they can't see the chosen target wich is for sure one of the other side in front of them. This is not the first time i get this problem, the last year 2015 i was practicing on another project and found that same issue. That time i just eliminate the Linecast check and let just make sure the ai is close enough to engage. Wich is not a good way to go really. Now i want to find a way to fix this problem and be able to go forward with my game. So now that i explain in detail my situation, come the question. Any of you have a good idea of how can i possibly even approach such an issue? I'm in the 4 o 5 day of trying to solve this shit problem. So in that time i was thinking very much and i get a number of pose but after all this time i think it going to worth the time asking here. Becouse to be honest i still have not a good clue on where to go exactly. And i'm get good number of clash points where i have to chose one solution or another and none of then is exempts of cons. One of my initial thought was to same as in my old project, just eliminate the linecast check and go with distances. So if i do this the Ai will not care about if target is actually in fire line or not, as soon as they get close are a target. But of coruse this get a lot of bad situations like an ai shooting at a wall becouse cant figure that is nothing to shoot at there and so on. Another one wich is what i'm trying to now but lead me to a more fancy code stuff. Is to check if the ai can see the target with linecast but if return false trigger another check. Wich make a loop over all npc in scene and check one by one wich one is more close to the AI. And finally check the distance of the pre-selected target and the attackrange. So if i can get this work it should fix the problem but even when im alredy write this it isn't workin properly died. And that's why i'm writing this to beging with. It's funny that after writing all this i'm start to think that i have to be fine with this last solution. But in case it wont let me know if you have a good way to approach this situation. It's really frustrating and i'm going have to probably re write a 1 thousand line of code Ai wich is a low hit on the ball's. Hope i was explicit enough and delivered enough information, if not let me know. I'm not sharing the entire code just becouse of the lack of comment's so if i share no one will understand it easily anyway xD. Thanks in advance for any response.

Viewing all articles
Browse latest Browse all 1875

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>