#πŸ€–β”ƒai-navigation

1 messages Β· Page 11 of 1

golden kettle
#

@sonic rain Hey quick query again on UAI, so he mentions on one of this slides that you can keep multiplying these utility/axis values together to get an overall result for the related action.

However he highlights that by default you will end up losing value with the more in the axis as you keep multiplying you just keep getting lower and lower i.e:

0.9 x .0.9 x 0.9 =0.729

So someone else came up with a fix for this where they applied an offset fix which allowed you to multiply with the offset and it stops the reducing of the average, which seems a bit long winded and complex.

Now my question here is really why bother doing all that when really if you want an average could you not just do:

(0.9 + 0.9 + 0.9) / 3 = 0.9

#

(sorry for so many edits, pressed enter by accident without shift lol)

#

The only logical reason I can see for doing it with the multiplication with offset addition is because division is more time consuming on CPU than multiply, but I wasnt sure if there was any other reason

#

from a quick check it seems on average CPUs an FP division is 5 times more expensive than a multiply or add, but even so I would imagine you need to do far more math to calculate the offsets and factor them in than the cost of a single divide (adds/subs seem to be about same cost as multiplication on fps)

#

posted in reddit gameai, Dave is a mod there so hopefully he will jump on it and tell me

sonic rain
#

Hey @golden kettle ! Yeah, I was also puzzled by that. My conclusion was: the multiplication is really needed as it has the power to scale up/down some value. See, a multiplication of a big number with a small number will cut it down a lot, in comparison to summing it up and doing the average. Something like this:

Considering two scores:
A = 0,9
B = 0,1

Sum: 0,9 + 0,1 = 1
Multiplication: 0,9 * 0,1 = 0,09

So, as a comparison of the results, the Sum will increase the final value, and multiplication will decrease it "a lot". When we get the sum and make the average, it still results in a "high" value, which would be 0,5

Considering the two same score values as above, and applying the average method VS the method presented by Dave Mark:

Sum and Average: (0,9 + 0,1) / 2 = 0,5
Dave's Method:

modificationFactor = 1 - (1 / 2) = 0,5
makeUpValue = (1 - 0,09) * 0,5 = 0,455
finalConsiderationScore = 0,09 + (0,455 * 0,09) ~= 0,131

Results in ~0,131

Comparing the results again, they are very different from each other and they express different design choices. With multiplications, we are always scaling one value with the others, which happens in a different proportion in comparison to sum and divide

Another thing that I noticed is that, if you have a value 0 as score, the results will ofc differ a lot:
Sum and Average: (0,9 + 0) / 2 = 0,45
Multiplication: (0,9 x 0) = 0

But even when performing sum and average, in case any zero, we could perhaps just say "ok, cancel the sums, result zero immediately"...but that's a workaround which might break the methodology

Why am I speaking about zeroes? Because, when designing my own curves these days, there is some usability value when you want to return zero in one of the curves as a way to cancel the other ones. Like: I'm combining 3 curves to know if I should use a Skill. One of the curves will return zero if the skill is in cooldown, aborting the whole multiplication

#

Showing a little bit about this Skill thing that I mentioned...these are my curves, on my tool (this is the minimised view, it can be expanded to see/define the curves better)

#

Their results are combined in order to know if the Heal Spell should be used

#

As you can see, the first thing that is tested is: is the skill in cooldown? (i.e it's cooldown value is > 0)

#

If it is in cooldown, zero it. This, multiplied by anything, will cancel it. So no, in this case, don't use the spell

#

If the cooldown is zero, then well, the result will depend on the others. But yeah, multiplication by very high or very low factors, while normalized, allows you scale the importance of doing stuff. I'm not sure if the same is achievable with sums and averages, perhaps it is! But it would be bit different, but it might be not impossible

left turtle
#

I have an AI that generate its own sequence of action based on parameters and avalaible resources. It's not a state machine for sure, how would you name that type of AI?

golden kettle
#

@sonic rain Thanks for the info buddy I have been in a meeting most of the day but yeah as you say the 0.0f results indicate STOP, whereas with a simple average it would just drag the numbers down a bit, not short circuit

real sonnet
#

Or perhaps if it's not goal-oriented and you made up a new kind of AI, give it a new name: Context Action Planning haha

#

Reactive Action Planning ? πŸ€”

trail lagoon
#

Hey my NavMesh base offset variable keeps resetting to 0 in Play Mode, any fix?

golden kettle
#

@sonic rain I also came up with a semi novel way to handle multiple things per utility, so I already had the notion of a sort of blackboard style object which was used by our existing framework. So by default it's keyed on ints (utility/consideration type) and contains whatever data you want but as its a <K, T> situation under the hood I have just added a slightly customised implementation with a composite key where its made up of utility Id and another possible Id, so if you just provide the utility type it only has one entry for that utility, if let's say we want to track all targets it's all under same utility Id but the foreign key (being the enemy Id) basically let's be have multiple entries under same utility Id. This not only let's me keep things a big simpler in terms of usage but it also let's me use the foreign key to lookup individual targets/tiles/abilities for that variable AND I can basically average or score all entries under that utility Id to get a feel for things, I. E get average party hp scores, or min enemy hp score etc, not sure if I will find some downsides more I get into it, but going ok so far.

#

@trail lagoon not a clue but this is more ai discussion. Would ask in general

left turtle
# real sonnet Reactive Action Planning ? πŸ€”

It has 2 state
Survival and Normal
In normal mode he has a "safe/agressivity meter" based on how much he is advantaged. They don't wanna get stalled but don't wanna be suicidal nether. It build his sequence o action based on risk/reward taking account his resource ex (mobility, weapons) and his target resource as well.
In survival it's as the name say, they are trying to drag you out until reinforcment or escape if they're aint getting any

#

i built it long ago without knowing anything about IA and was wondering if it has a name

golden kettle
#

Fuzzy logic?

golden kettle
#

There is only really names for conventions or architectures, you have some fuzzy logic with a transition to states or something so I wouldn't say it's a specific convention just a mix of a couple of approaches.

golden kettle
#

You may get lucky but I would ask in general or something too as I assume this is a lot smaller an audience than there and the issue isn't the ai or whatever its just the editor/mb ignoring your value for some reason

sonic rain
left turtle
#

thats what i though, some people make it seem there's only a few way and everything fall into one of the category. For context it was a tactical rpg game

errant quail
#

i made my ai yaay

#

@golden kettle thanks mate

golden kettle
#

Np buddy

golden kettle
#

But at some point someone has to name a convention before it can become standard, look at Utility AI/Infinite Axis AI, it was an evolution of fuzzy logic and Dave gave it a name and now we all kinda agree on what it is

#

Like if I said to you, I have an object that listens to value changes from somewhere and contains a read only copy of the most recent value but you can be notified on changes to the value.

What is it?

#

(It's a computed property/value, but if I just said computed value up front people would be ons ame page from get go)

left turtle
#

i made a couple of IA in the past without knowing anything (competitive programming, where my AI had to beat other AI), i had a pratical diploma so I could code but not a university one so i barely knew of any concept I was actually using or found out myself xd. The only time i used an external source was when I used genetic AI cuz i read about it and though it was cool.

left turtle
golden kettle
#

Lol well it's called a computed by most people πŸ˜‹

#

But as you say until you know the common terms it's all nonsense, like when I first learnt factory pattern had a name, fresh out of uni I didn't have a clue about all these conventions and terms. It's only really when you need to work with others that there is some value in having common terms that everyone can understand

#

If you tend to work alone more doesn't matter what they are called until you come to discuss it with someone else

left turtle
#

Nah i dont work alone, but prefer to use easy wording that everyone can understand

#

including non thecnical people

golden kettle
#

That's a different thing then, like at work if I say to someone "make sure you plug in the repository via the di module and add an aop transaction handler" I'm only gonna say thst to a technical person

left turtle
#

and if i take shorcut ill only talk in a pratical manner, no weird word

golden kettle
#

But these words are not weird, they may be unknown to you, but assuming it's a common industry/technical standard term there is more merit following same vocab as everyone else

#

Simplifying technical jargon for muggle business people is a separate skill, but again before you can translate what the architect is spewing you need to know what his terms mean

#

If he's speaking his own flavour of terms rather than common ones everyone's gonna get confused

left turtle
#

my uni teacher didnt like it, but i quit cuz it felt like a waste of time, job secured, wasnt getting more money, was losing years of salary/experience

#

in the job i just learn term on the fly when i need them

#

by talking to people

golden kettle
#

You don't need degrees or anything these days, plenty of materials to learn and improve online, but regardless of this stuff the quicker you can all speak same terms and all understand each other the better, same in anything

left turtle
#

it's a bit like linguistic immersion travel vs learning everything from home then move

#

i prefer the first approach

golden kettle
#

Sure sure, but as long as both arrive at same destination I wouldn't care, its jsut if you purposely didn't want to adhere to common terms for whatever reason that I would be worried

left turtle
#

oh don't worry i'm fine with term, im just not fine with how teacher hard punish you for not using the exact wording they want

#

and again, i'd say it depend on teacher

golden kettle
#

I had a tutor refuse to accept my assignment because he said we had to make a website about anything, so I just made a website about cheese with horrible js effects and midis lol

left turtle
#

but when i was young and didn't know how thing work i though i absolutely needed a university degree

golden kettle
#

(this was like 20 years ago, not modern webby swishness)

golden kettle
#

I think that's one of the key things, knowing what to learn

#

I had this debate with a chap who was streaming his game dev, that I feel as time goes on there is less and less merit in paying for a degree in tech

#

The only major benefits are potentially the road map of what you learn and possible help in getting some work experience

#

If you got a university module road map and youtube each bit you could potentially still be as competent

left turtle
#

one time my teacher was trashtalking video games so in a argumentative essay i picked the subject "literrature shouldn't be in educational system", i failed but and I was able to prove she wasn't impartial in my evaluation haha it felt so good

#

my parent just though i was making trouble for nothing Β―_ツ_/Β―

left turtle
fallen nest
#

Not necessarily, the issue isn't with complex collisions cause it would be used with path finding. But the issue is that I can't figure a good way of getting around an obstacle overall. Someone had managed to do it without making the literal obstacle avoidance by implementing a system that would avoid certain vectors. The issue is I can't figure out how to make it avoid those vectors and also go the right way.

fresh jetty
#

Hey does anyone know how to fix that? I'm getting it only on the second "enemy" object, on the first with the same mesh agent settings works perfect but on the second "enemy" I'm getting this error (before bake map fixed it, but now it doesn't change anything)

#

oh I see this problem exists only on custom agent type :/

fresh jetty
alpine glacier
#

1 for unity navmesh if you have a stationary object that does not move at all, why do people still bother to set it up as a navmesh obstacle in tutorials when you can literally just tick 'height mesh' then bake works exactly the same?

#

this way it excludes it from the navmesh entirely

#

which in my opinion is not only less work but will work way better has your game becomes more complex

#

pls @ me when replying

alpine glacier
#

Basically when I run it on my game there is a significant delay in the enemy actually starting to move, I am not entirely sure what is causing this or how to fix it? I am on quite a powerful PC so it can't be the processing power? Additionally I thought it was because the enemy was note entirely on the navmesh or falling off it, but its not that either?

#

I think the most likely issue is, its recalculating the movements too often

#

but I am unsure how to fix that?

alpine glacier
#

here is a video

#

of the issue

#

the video actually makes it look like they are moving fast, but sometimes they won't move until I go near them, drag them in the editor screen or even move at all

#

pls @ me when replying

sharp mulch
#

hello how can i make that the navmesh is on the ground and not floating like in this picture

fresh jetty
#

Hi does anyone know how can I make detection with camera for AI something like on the image? I mean if player is behind of the wall on camera look then don't detect, otherwise detect. I saw some ways with GeometryUtility, raycast or viewportpoint from world and nothing from them are works as I want, does anyone has better idea?

solar oriole
#

Hi i was wondering if anyone knows what could be causing this issue i'm having with my navmesh agent.

#

On scene play my navmesh agent goes from a normal rotation to being stuck at a -180 x rotation

fresh jetty
#

I had the same problem, it was caused by invalid exported fbx model from blender

solar oriole
#

In your navmesh agent can you pass in coordinates directly?

#

For the destination

#

instead of a mouse position etc

alpine glacier
# fresh jetty Hi does anyone know how can I make detection with camera for AI something like o...

Enemies usually have eyes, right? So lets give your enemies some vision! In this video we're going to add a really simple but really effective field of view, field of vision, cone of view, line of sight... Whatever you want to call it, to your enemies!

We're also going to make sure that the enemies can't see you through walls and AS A BONUS! We...

β–Ά Play video
GitHub

A simple Field of View system for the Unity Egine. Contribute to Comp3interactive/FieldOfView development by creating an account on GitHub.

vast viper
#

So i want my navmesh agents to NOT avoid each other, meaning it's ok if they're clumped. Their collider is set to trigger, radius to 0f, but whenever they walk "through" another agent, they still make way / push each other when passing

copper current
#

oof i hit a lag spike there

wind crypt
#

Hello anyone know how to check if agent has complete path to reach destination or not?

brave sorrel
#

Anybody knows what i can do against this?

slender wing
# brave sorrel

change your ml agent version to the supported version. version 2.

tight bison
#

my question is the same as akka's, is there an efficient way to tell if the agent has reached the destination?

brave sorrel
tight bison
#

I'm tagging a bunch of objects having them with a tag "LightObjects" and "HeavyObjects" and just checking the furthest distance from the agent and setting the destination to it

brave sorrel
#

i mean you could do couple of try runs, where you try different things and you can compare them in tensorflow

river fern
#

So I made an ai but when it goes to the waypoint it just turns circles can some 1 help me?

real sonnet
#

Do you try to reach exactly the position ? If so, you should instead just check if distance < someThreshold where the threshold is something small but not zero, like 0.05f for example

#

And when you reach last waypoint, you could just stop updating the position (stop moving)

wispy bison
#

Hello, world! I am currently working on an arcade racing game and I was wondering if anyone here knows any resources that could help me get started learning how to develop AI opponents for it.

#

I did some searching on my own but, besides some tutorials on YouTube, I didn't find much.

dim needle
winged relic
old kiln
#

nav mesh time

#

how to solve this issue

old kiln
# old kiln

my nav mesh agent is falling through ground

alpine glacier
#

hey guys, im a bit new to programming ai and stuff. currently trying to get follow target working after click to move is complete.
heres my current code: https://hastebin.com/alimarujog.csharp

#

(obviously wrong since it doesnt work xD)

river fern
low stone
#

hi am starting out in untiy, i want to create an AI for my enemy (2D platformer game) melee attacks or range attacks what is the best way to do so, any video on that topic would be helpful :)

alpine glacier
river fern
tight bison
#

I'm having a bit of a problem here, I'm making my characters go to specific objects. When they do they'd just send an output. Now I'm trying to check if the distance to target is smaller to stopping distance but sometimes there'd be characters that are just a above the stopping distance by a couple of float points

#

note the distance to target in the inspector tab

#

how do I fix this

old kiln
old kiln
#

nvm I solved

#

fix is just to bake it from navigation

alpine glacier
winged relic
#

basically try commenting out else { m_minion.SetDestination(m_master.position); } or removing it.

#

it's overriding what your mouse click does in the next frame.

#

however I'm making some simple assumptions just looking at your code, I don't navmesh πŸ˜›

#

you also appear to have 2 references to navmesh agents, which could be confusing... do you know if you are triggering the correct one

alpine glacier
#

at this point im at such a stress trying to fix this im not even certain at this point haha

winged relic
golden kettle
#

Related to a query I had a while back to do with Utility AI, so I have a basic Utility AI framework and am trying to build up a suite of considerations and actions, however im struggling to wrap my head around the best way to collate the available information.

#

So for example I have a consideration for if something needs healing, and allies who can heal can monitor that utility on others, and same on enemies to know which one the weakest is. So when factoring in the best enemy to go for I ideally need to know considerations for:

  • Distance
  • How Low Their HP Is
  • How Low Their Defenses Are
  • How High Their Damage is
#

as if something is close but with high HP but something else is slightly further away with lower HP I should be going for that, but the thing is scoring alone (utilities multiplied) isnt enough alone, so im wondering about adding weights to things to make them more important, like:

Enemy 1

  • Dist: 0.5
  • HP: 0.8
  • Def: 0.2
  • Dmg: 0.2

Enemy 2

  • Dist: 0.4
  • HP: 0.3
  • Def: 0.8
  • Dmg: 0.8

So at a high level Enemy 1 is close-ish, very low hp but has high def/dmg, and Enemy 2 is further away, more HP but far less def/dmg. Ideally I would want to go for Enemy 1 as the low HP being higher is more important than other stats, so is it as simple as just adding a weight modifier and multiplying the HP by that?

#

I know its always mentioned in the GDC talks about adding weights but its discussed at actoin level not consideration never delved into deeply so was wondering if anyone else had any experience/thoughts on it

winged relic
#

@golden kettle isn't this where Curves come into play, it allows you to artificially inflate important stats or down others.

golden kettle
#

that gives us the 0-1 score for a consideration

#

so for example HP is using a quick rising quadratic curve to take the 40/200 hp for example and run it through the evaluator/curve to yield 0.8 (i.e you want to heal)

#

if it were linear or a more relaxed curve I may get 0.6 instead or something, so yeah they do influence the consideration value, but only in isolation

#

so in this case when I am formulating composite considerations or even an action I am wanting to imply that certain utilities are more important than others

#

as every unit has the notion of how close to death they are (needs healing), how strong they are (rough damage output), how defended they are (rough defenses) and other bits

#

so scoring them and knowing about them in isolation is one thing, but when you want to bring them together in some cases, low HP utility may be far more important than how high a damage output someone has

#

but as there is little REAL world info on this approach, the main gist is you just multiply them all together and at action level maybe multiply it based on a priority

#

but I want to add a weight to existing utility values when factoring them together with others

winged relic
#

I was reading a chapter which maybe relevant, it suggesting having a consideration to asses "survival chance". I.e. don't run to repair if it puts you at more risk, which could be flipped around to don't engage if chance of survival is low. Basically it maybe alter your list of considerations to include some more expressive values.
Hope that makes sense πŸ˜›

golden kettle
#

but even so, if I have 3 utilities

#

lets say health, risk, distance

#

risk may be far more important than distance

#

I guess risk is a bad scenario as thats contextual

#

but in some cases you may want to scale utilities somewhat

#

but again this raises another question, around composite utilities, currently I am building some utilities off others, like computed value

#

but you could say "dont do that, just make it an action"

winged relic
#

I know what you mean and can't help but think as I often have been this past week "Am I overthinking this", you maybe seeing a problem that does not exist. If the information in is good, the decision should be too

golden kettle
#

yeah, I feel that this is a valid issue, as right now im working through targetting logic and its tough getting it to know who to target as early on all the values are pretty similar as even if HP starts to fall on one, its kinda ignored somewhat by the other values dragging it down

winged relic
#

I'm in the slow process of building my UAI (just in spare time, so going slower than I'd like), I like the idea of Utilities to support other utilities and have indeed built this into my code. How it works in long run is yet to be seen πŸ™‚ But I approve of the idea!
Targetting is a tough one, I was considering handling this logic elsewhere but that feels defeatist. So much as you are probably doing I've now added some inputs to my top level decision, so it can be assessed in UAI. It still feels like catching air though πŸ˜„

#

For me though I'm going to pull in some values from influence maps which should be the deciding factor / extra weight

golden kettle
#

at the moment I am quite happy with the overall implementation, as I have composite keys and also contextual advice so rather than it just being "Go Attack" it also contains a contextual accessor which lets you knwo what you should be attacking

#

due to this I kinda went with Considerations/Advice notion

#

as this doesnt outright DRIVE actions, it just provides high level weighted advice with context, i.e Attack X, Heal X, Move To Y, Take Cover At X and then when that unit takes its turn it looks at top rated advice then decides to go with it or not

winged relic
#

I see, interesting approach

golden kettle
#

as if all advice is pretty low or around same amount its more likely that a random outcome wont matter, but if one is far ahead of the others it makes more sense to follow it, but the decoupling of the actions and having it more a steering sort of system makes it easier to just consume anywhere

winged relic
#

do you have influence maps at the moment or how do you handle "if two enemies are close together and a third separated" type situation or does that not exist for you?

golden kettle
#

its just basic distance checks

#

like the distance utility is literally a Vector2.Distance style lookup

winged relic
#

if you have those scenarios, it maybe worth making up a simple influence map to help gauge the number of enemies in an area. that way you can spot targets alone, which might be more distant but are more vulnerable.

golden kettle
#

(run through a clamper and curve)

winged relic
#

I'm going to have to run, eating into work time. perhaps someone else with more experience will chime in πŸ˜‰

golden kettle
#

possibly, if I wanted to make it more complex like that I could always query the enemies distance utilities to other allies/enemies and just find an enemy with distances to other allies being low/high etc

winged relic
#

the idea of influence maps is that it can save those calculations by simplifying the problem, but until you build one it can seem hard to picture how they help / can be useful. I'll leave it with you, best of luck!

golden kettle
#

thanks, they mention them in the GDC arenanet thing, but I cant see me getting much benefit out of them atm, all values are cached and only refreshed when they change (bubble up) or a predefined period passes in which they are deemed stale (i.e after a turn) so little overhead in them

low stone
#

Hi am trying to make a enemy AI, am facing a problem with my game crashing whenever the player attacks in the trigger collider of the enemy (this collider should make the enemy move toward the player if he enters the range), i really don't know where did i mess up. but i have a feeling something is wrong with my combat script or the enemy damage script

#
public class combat : MonoBehaviour
{
    // Start is called before the first frame update
    public Animator animator;
    public Transform attackPoint;
    public float attacking = 0.5f;
    public LayerMask enemyLayers;
    public int attackDamage = 20;
    
 

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.E))
        {
            Attack();
        }
    }

    void Attack()
    {
        //Animation
        animator.SetTrigger("Attack");

        //detect enemy
        Collider2D[] hitEnemies = Physics2D.OverlapCircleAll(attackPoint.position, attacking, enemyLayers);

        //Damege them

        foreach (Collider2D enemy in hitEnemies)
        {
            enemy.GetComponent<enemy>().takeDamage(attackDamage);
        }
    }

    void OnDrawGizmosSelected()
    {
        if (attackPoint == null)
        {
            return;
        }
        Gizmos.DrawWireSphere(attackPoint.position, attacking);  
    }

}```
zealous mantle
#

What does the enemy script look like, specifically the take damage function and the one that handles the range.

real sonnet
#

Basically yes you can group Utilities by priority

#

and assign weight to it

#

Or don't even consider the next bucket if current is above some threshold

#

"Eat, sleep and such will always go first before watching TV and socializing"

#

You can come up with way more reasoners/selectors than "Pick the highest score"

#

you can have full-random, weighted-random, best or random within the n-first results, first to score above a threshold, and so on

#

lot of combinations

#

Hope that gives you ideas

low stone
# zealous mantle What does the enemy script look like, specifically the take damage function and ...
public class enemy : MonoBehaviour
{
    public int maxHealth = 100;
    public int currentHealth;

    public Animator animator;
    // Start is called before the first frame update
    void Start()
    {
        currentHealth = maxHealth;
    }

   
    public void takeDamage(int damage)
    {
        currentHealth -= damage;

        animator.SetTrigger("hurt");

        if (currentHealth < 0 || currentHealth == 0)
        {
            Die();
        }
    }

    void Die()
    {
        animator.SetBool("isDead", true);

        GetComponent<Collider2D>().enabled = false;
         this.enabled = false;
         Destroy(this.gameObject, 5f);
        //GetComponent<Animator>().enabled = false;
    }

    

}
#

tbh if u have a good tutorial on enemy AI that would work too.

molten sequoia
#

Is the editor freezing?

low stone
#

no the game view is freezing

molten sequoia
#

Game view only?

#

Can you move things around through scene view?

low stone
#

yes i can

#

everything else works apart form the game view

#

as soon as the player does the attack in side the trigger collider (child object) the game pauses

#

also a weird thing i noticed, i added a new collider on the enemy object (total 2 colliders now) also marked it as a trigger but if the player attacks inside of the trigger collider the enemy still receives damage

#

@molten sequoia

zealous mantle
#

If the game is literally pausing (the pause button at the top of the editor is pressed) , it means you have a runtime error. Is there no red errors in your console when this happens?

low stone
#

yes that seems to be the case

#

here's the error message

real sonnet
#

SHould have begun with that πŸ˜›

#

What is line 40 in the combat script

real sonnet
#

Uhm did you add/remove code between the screenshot and now ?

#

THis line is suspicious and often leads to mistakes

#

enemy.GetComponent<enemy>().takeDamage(attackDamage);

low stone
#

ah yes i removed the unnecessary start function

real sonnet
#

the error is basically saying that something you expected to be set is in fact NOT. So when you try to access it, you get some NullReferenceError

#

Alright

#

So, you think you'll get only enemies with that, but in fact it seems you catch objects that don't have the <enemy> component (script)

#

(That's not really an AI question)

#

Multiple ways to fix this, do you know where to begin ?

low stone
#

ofc i don't 🌚

real sonnet
#

My first guess would be you have more things than enemies in your enemy layer or layers messed up. You can begin with logging what's colliding

#

In the first line of the foreach, try to debug log enemy.name

low stone
#

should i comment everything else?

real sonnet
#

nope

low stone
#

ok

#

u need the console view right?

real sonnet
#

in the end you would probably cache the script and check if not null, something like this ```cs
var enemyScript = enemy.GetComponent<enemy>();
if (enemyScript) {
enemyScript.takeDamage(attackDamage);
}

#

So the collider and the enemy script aren't on the same gameobject, right ? Can you show how the gameobjects are set up in the hierarchy view ?

low stone
#

sure

low stone
real sonnet
#

alright, can you try the code i posted

low stone
#

should i write it in my attack function?

real sonnet
#

Replace this line enemy.GetComponent<enemy>().takeDamage(attackDamage);

low stone
#

alr

real sonnet
#

I think you have the enemyTrigger on the enemy layer too. Up to you to decide if it should be or not ^^

#

the null check should be enough though

low stone
#

i think that seems to be working but still have an error message in console

#

and yes i do have the enemyTrigger on enemy layer

real sonnet
#

The first is from the Collab package, I can't do anything about it :p

low stone
#

ah well

#

TY β™₯️

real sonnet
#

You're welcome, happy coding

uncut mortar
#

im confused at why i get this error

#

( the graphics )

#

( ping me pls )

#

i have this like this

surreal flax
#

have you baked your navmesh ?

uncut mortar
surreal flax
#

... check

low stone
#

why isn't the pathfinder tool working :( the background layer is set correctly

is there a way to create a navigation grid manually?

#

nvm i fixed it, silly mistake

#

:P

#

ok so real problem, every time i try to make the player jump when the AI path finder is running the player animation is stuck on jump (the player do not jump but can be moved around on the x axis)

#

i really don't know where the problem is at, probably at the animator

#

am using charterer controller 2d script for movement

final sleet
#

Does anyone have opinions about locomotion/full body attack animations/rootmotion?
I've got my units using a nav controller and a blend tree for walking, but when they do an attack that's animated with their feet standing still they slide around as the nav controller moves them around.
I can do any of the obvious things like turning off nav and using rootmotion for the attack, using avatar masks to keep the lower body doing locomotion and playing the attack on the upper body, etc. - but would really like to talk it over with someone who's played around enough to have opinions and knowledge about what works well.

uncut mortar
torpid stump
#

Make sure that the Objects you're baking the NavMesh for are marked as "Navigation Static"

#

(top right corner in the Inspector there's a "Static" checkbox with a dropdown next to it)
(also, used bad wording there, i don't mean marking your actual NavMeshAgent as "Navigation Static", but instead the Objects where your NavMeshAgent should be able to move on)

fallen nest
#

So I'm having trouble figuring out how to make a good context based steering system. I noticed from a tutorial through Godot that they use a danger value that instantly turns off the interest if there's a collidable object, but the issue with that is if the target is against a wall, it's not going to go towards the target. There was a system someone managed to make where they some how don't use any collision detection, and just try to avoid specific vectors.

Is there anyone who's managed to do that, or have a successful basic context based steering, or local avoidance ai?

#

I guess the main issue is I can't figure out to get proper danger values

final sleet
#

@fallen nest there's lots of ways to do it, but the devil is in the details.
What's your project, how can the AI move, what sets the targets, have is the ai pathfinding, etc.

#

Was the tutorial that 2d game with the skeletons?

fallen nest
# final sleet Was the tutorial that 2d game with the skeletons?

Not sure which you're referring to there, but it was a Godot tutorial talking about how to implement context based steering which contains a similar way to how I want to do it. Basically, the agent is suppose to be able to go through different directions (no rotations), but to figure out which direction to go, it's meant to act on a dot product that favors going towards a target position. However, you need a danger value to counteract the value to not run into a wall, and figure out a way to assign that danger value so that it only applies to actual danger and not when say it's hitting a wall that you need to go towards

#

And that's primarily my issue, figuring out how to make it so the danger value works properly enough to where we know it's okay to go in that direction despite it hitting an obstacle

final sleet
#

I think the way he got it working was to calculate a value for every direction

#

If it gets you closer to a desirable goal it gets a positive value. If it's pointing a bit towards the goal it gets a smaller positive value. So that allows multiple desirable goals.

#

And then if there's a wall or something a little undesirable there's either a penalty, so it'll prefer to avoid running towards walls...

#

Or if there's something to avoid like an enemy he was just clearing that direction entirely so it couldn't be chosen.

#

Which means if the enemy is between the AI and the goal it can still move towards the goal at an angle to avoid the enemy.

#

I don't personally use that style of avoidance, I believe there's some local Maxima, like if you move towards the goal at an angle then you might get to a point where the enemy is near the goal and you can't walk closer and get stuck. Usually you build in a strategy for that, like circle to the right or some randomness to add in motion that hopefully breaks the deadlock. It also struggles at handling walls and multiple instances.
But those might not be issues depending on your game style.

fallen nest
#

Because the main issue I'm having is using A* but not being able to figure out how to avoid other agents so they don't run head on, or go in the same direction for that matter

final sleet
#

Hmm, OK. So you know how the dot product will give you the component of a vector perpendicular to another vector?

#

Actually, what I suggest you do is forget about dot product for now, and figure out how your logic should work and how you can show it on the screen.

#

If you're trying to get to a goal while avoiding an enemy, can you do something like drawing a green circle around the goal and red circles around the enemies.

#

Then a line in each direction you can move. Something visual like that so you can see how it's making decisions and spot if something is going wrong.

#

Then you can get the angle between the possible direction and the goal to get the desirability of going that direction. Smaller angles are more desirable.

#

When that's working start layering on your other requirements. A small angle between a direction and an enemy makes that direction less desirable. Closer enemies have a bigger impact. Walls make a direction less desirable.

#

Do you need to pathfind around walls? If so you can astar a path and each turn in that path is a potential goal. Can't go direct but can go to that turn in the path? Great!

#

After the logic is working properly you can worry about making the calculations more efficient and using dot product.

#

But if you're using A* already I'd probably just use even more A* as my solution rather than something like this.

fallen nest
#

Also that's the other issue I have in figuring this out

final sleet
fallen nest
#

Figuring out how to track walls and enemies

final sleet
fallen nest
#

Because I've tried raycasts, however their very inefficient, they can get the agent stuck on walls from clipping the corner

final sleet
#

How are you building your nodes for the astar tree?

fallen nest
final sleet
#

Aha

#

That's a great asset, but throws a spanner in the works

fallen nest
#

Yeah it works perfectly for one ai, but I'm trying to figure out a way where multiple enemies don't bump and run into each other. Aron has this in their $100 pro package with RVO/Local avoidance ai

final sleet
#

I was about to mention that

fallen nest
#

But I'm just mostly trying to do something simpler and don't have the money for that lol

final sleet
#

It's good for traffic jams but won't make the air avoid going near enemies

#

So you probably need your own solution anyway

fallen nest
#

The one method I was wanting to go towards is explained pretty well in this video https://www.youtube.com/watch?v=6BrZryMz-ac

Combat keeps the player engaged as they explore my game, so I improved how the enemy interacts with the player and their environment. This tweak made combat so fun that a tester spent over an hour repeatedly fighting a handful of enemies. At this point I knew I had an engaging combat system!

Howdy, and welcome to the 12th indie game devlog for ...

β–Ά Play video
final sleet
#

Is your level a grid - or could it be a grid? If you know how to program it might be worth writing your own A*

fallen nest
#

It is, it's using tilemaps

final sleet
#

It's a fairly useful skill to have, because you can then pack a lot of information into the pathfinding graph.

fallen nest
#

Probably could, I'll have to think about it

final sleet
#

I've got to go to bed, we can pick this up tomorrow. But if you're not scared of reinventing the wheel what I'm thinking is:

  • make your own A* graph from your tiles. Then you'll know where the walls are by seeing which tiles aren't connected to their neighbours.
  • make your A* pathfinding work with your graph
  • Add weighting to the level data (moving over grass is more desirable than moving over mud)
  • then add weighting for things like danger. Moving near an enemy is less desirable than moving away.
  • since weighting in A* is essentially the same as the path being longer - i.e. it has a higher cost, your AI can then circle around an enemy to get to the goal, but can still pass close if there's no other choice. And they can choose a further away goal with less enemies.
#

That tutorial has fun movement but no real pathfinding. Note how they all move in existing open areas. The obstacles just stop them moving, but they have no smarts about going around obstacles.

#

You could add something like that on top of A* if the pathfinding tiles are large enough, to decide on movement within the tile. But I probably wouldn't. I'd just put a pathfinding cost for moving over other units or something and that will already cause them to spread out.

#

And recalculate periodically, since everything is moving. Don't just calculate a path and assume it will stay clear while you walk it all the way.

alpine glacier
final sleet
alpine glacier
#

I came here to try and figure out weighted attacking... and now I'm like, I want this for my movement...

final sleet
#

You can bias movement like that with other methods too

alpine glacier
#

Yeah, I just need to look into it now.

My current problem with the above method is that when i started to implement weighted attacks, I found that they would attack, that attack would be weighted less, then it'd get to the point where they're waiting a long time between attacks as that weighted value is now so low.

final sleet
#

I'm currently working on combat and I'm planning to have them circle like that, inspired by that video... cavemen hunting a mammoth...

#

But with different techniques

#

Gnight!

fallen nest
alpine glacier
fallen nest
#

If you can replicate it, I'd be shocked cause I've been spending weeks trying to replicate it lol

#

But I just can't seem to figure out how they did it, unless they did what I think they did

alpine glacier
#

Realistically, it shouldn't be too hard. It's VERY close to what I already posted.

#

But they're using some different/smarter things.

fallen nest
#

It shouldn't be, but my main issue is figuring out how to know where undesired positions are at

#

cause they said they don't even use any form of obstacle avoidance, it's purely by coincidence that it works that way.

alpine glacier
#

If you refer to the "Forget Real AI" video I posted, its probably similar to that.

fallen nest
#

Yeah I'll have to check that one out

alpine glacier
#

Scan the scene for boxes, apply negative pressure to them to push them away.

#

Though the smarter solution wouldn't be "Scan the Scene" and probably just a Physics2D.OverlapCircleAll and go from there.

#

EG like this.

#

Player being the blue circle top right. Green Circle being the OverlapCircleAll

fallen nest
#

Doesn't a overlap circle only work if there's multiple objects, not tilemaps?

alpine glacier
#

We talking about Unity Tile Maps? In which case, if it has a Collider it should hit it.

fallen nest
real sonnet
#

You can sample positions around your agent and draw raycasts from there

alpine glacier
#

^ Also works.

warped idol
alpine glacier
#

I'd actually assume Raycasting might be the better option here.

fallen nest
#

Like basically I would use raycasts from the position of the agent to the direction vector, though boxcast is the only one that really works because raycast doesn't keep track of corners

warped idol
fallen nest
real sonnet
#

Article looks good

alpine glacier
fallen nest
alpine glacier
#

Ah yeah, I misread how CircleCast works.

real sonnet
#

Raycast is enough. Maybe shape cast for a big boss eventually ?

warped idol
#

I setup direction vectors and use them for raycasts

fallen nest
warped idol
#

I do
position + _contextDirection[i] in my raycast checks

fallen nest
#

Ah I see

warped idol
#

but yea same thing

fallen nest
#

But yeah no, my problem isn't necessarily figuring that out, it's figuring out how to properly add danger to the mix. Can't use dot product with the collider, can't use distance between the collider and the agent, and can't do anything that would instantly negate a direction.

#

Though unless the distance is used like in the spring method video, perhaps. I'll have to definitely try that out

warped idol
#

Right now for me the danger values are just 0 or 1 if the raycast hits

#

I'm using this for 3D so that why I create a Vector3 for the direction

#

Could use distance to scale between 0 - 1

alpine glacier
#

Sure wish I paid attention in math class now. :^)

wary ledge
#

I'd assume it would be something like, get direction of player, get the closest angle assign it at as 1 and then slowly reduce around it?

warped idol
#

This is just for following a target atm

wary ledge
#

Yeah that's fair. I was curious. I guess that's where the dot comes into play

#

Thanks for the reply though!

warped idol
#

Right now I'm zeroing out a direction with a danger value but I'm thinking about changing it

wary ledge
#

I assume as well that if I add a "Danger" to the player as well, while still keeping them interested, that might make them strafe around the player as well.

warped idol
#

potentially. I haven't figured out cool ways the set the interest yet lol

wary ledge
#

Lol

#

I'ma play around with it tonight, I might pop back in.

warped idol
#

Cool

wary ledge
#

Cheers for the code sample though, was struggling at the setting the interest.

wary ledge
# warped idol Cool

Just out of curiosity sake, have you done any debugging with your code? Like drawing rays?

warped idol
#

I'm doing that now

wary ledge
#

I feel like some of it is off from me mucking around with it.

warped idol
#

I did add something to the GetContextDirection

wary ledge
#

Seems to be working as expected now.

#

Though I am having issues where its still getting stuck on some things.

Or it can't choose between going left or right.

warped idol
#

That's where you'd play with setting the interest values

wary ledge
#

Yeah, even just drawing it out still seems wrong though. Like somethings missing.

#

Things that I noticed:

If the Vector2.dot is a negative it seems to fuck with this, as such, I fixed this by still having some very low interest to go backwards wherein the rare occasion, you'd want to. I need to smooth it out though.
Also, I feel with how I calculate my direction (EG: Just getting the best) is the better option? I could be wrong here though, but I feel thats what he was doing.

warped idol
#

I change the range of the dot product values to be 0 to 1 instead of -1 to 1

wary ledge
warped idol
#

Yea that's why I blended the direction interest vectors by averaging them

wary ledge
#

My idea was weighting the direction to be higher in whatever velocity youre already traveling.

warped idol
#

could do that as well

wary ledge
#

I feel that doing that might add for some interesting physics to it as well. Via if they get knocked back.

#

I just dont know the best way of doing that would be.

#

Oh... Well...

#

That was easy, and turns out exactly how I'd expect... Wow...

#

I have my Distance set to 1 and Howmany set to 18 in this case.

wary ledge
#

Current problem I need to solve now is stopping them from getting too close.

barren latch
#

What is the best way to handle AI in other scenes?

#

For example I move from scene 1 to scene 2, wait for 10 seconds and then move back to scene 1. I want the enemies in scene 1 to have moved as if 10 seconds in that scene had passed

wary ledge
barren latch
#

That could work

wary ledge
#

And of course store their Pos.

barren latch
#

It may be a bit more complicated if i still want them to have fought/ damaged things but it wouldn't be too difficult to come up with an approximation

wary ledge
#

At the end of the day, just store all that information.

I know Unity has the option now to load multiple Scenes. That data might be stored if loaded/unloaded Async? But i'm not sure.

barren latch
#

Ill have to look into that. I'd like to maybe have it so that my main hub is always loaded to process npcs actions etc

wary ledge
#

@warped idol , Any more luck/progress yourself?

warped idol
#

Nothing new yet

wary ledge
#
if(hit){
                danger[i] = distanceFromTarget / (1f + hit.distance * hit.distance * hit.distance);
            }

and

interest[i] -= danger[i];

Produces some interesting results.

#
for(int i = 0; i < interest.Length; i++){
            if(interest[i] != 0){   
                Debug.DrawRay(transform.position, rayDirections[i] * interest[i], Color.green);
            }
        }

        for(int i = 0; i < interest.Length; i++){
            if(interest[i] != 0){   
                Debug.DrawRay(transform.position, rayDirections[i] * danger[i], Color.red);
            }
        }
#

Inverse cube on the distance from the danger target makes it so the closer you are to said target, the more it'll push you away.

warped idol
#

Nice! I was going to look into that as well

wary ledge
#

The other thing I noticed was that the https://kidscancode.org/godot_recipes/ai/context_map/ uses a path. While this will help it move out of the way of some things, if you give it a full wall, it gets stuck. While I (Or we) could add A* to build a path to the target and use that as the target vector, that seems sort of moot at that point.

It looks like in Game Endeavor's video, he takes the the opposite of the negative value and adds it to the other side. (EG: If there's a 0.5 negative value at 90 degrees, he subtracts 0.5 from the intent at 90 degrees and adds it to 270 degrees. See 3:50)

#

Or something like that, because at 2:59 in his video it seems slightly different.

#

But I am 90% sure he selects the best line, vs the calculated normalized vector.

wary ledge
#

(Mine Right, his left. Size and everything matched up via screenshot)

Well I'm done for the night, this is the best I got. For some reason my values are a little bit further to the right when they shouldn't be.

I cant figure out the exact reason tonight, but, its at least progress.

fallen nest
#

Did you have two sets of lines, one being danger, and the other being interest? Cause that's what it's looking like from your side.

wary ledge
#

Blue being the chosen direction

fallen nest
#

So it's two sets of arrays like the Godot tutorial

#

2 questions though, are you using the dot product of the danger area, and how are you going to detect the danger in an efficient way

#

Unless you place red marks around the level as obstacles

#

Which has been in the back of my mind to do, but it feel like it wouldn't work effectively or even properly considering you'd have to add enemies avoidance mark

fallen nest
wary ledge
wary ledge
#

Simple fix to that though is Raycast your objects and circle collide with anything else.

#

Β―_(ツ)_/Β―

#

Orincrease the amount of rays

wary ledge
#

Figured it out. Smiles.

He seems to make his dot value tighter though for things he dislikes.

#

But yeah.

wary ledge
#

After playing around with it a bit.

I feel that there might need to be A* still involved.

wary ledge
#

(Confirmed, I just popped into Game Endeavor's Discord and he replied to my questions)
He uses a Node Based A* for path finding to move around town/stay on the main path etc, while keeping things simple to avoid concaves etc.

fallen nest
#

Or if it's suppose to be applied directly on to the agents position

wary ledge
fallen nest
wary ledge
fallen nest
#
    {
        Vector3 intention = Vector3.zero;
        Vector3 tp = transform.position;
       
        Vector3 direction = GetDirection(tp,targetPos);
        float distance = Vector3.Distance(tp,targetPos);      

        float targetDistance = 0.1f;
        float targetSringStrength = (distance - targetDistance);
        intention += direction * targetSringStrength;

        foreach (Vector3 obstacle in obstacles)
        {
            // GetDirection gets the normalized direction from the hit.point from tp
            Vector3 direct = GetDirection(tp, obstacle);
            float dist = Vector3.Distance(tp, obstacle);

            float springStrength = 1f / (1f + dist * dist * dist);
            intention -= direct * springStrength;
        }

        if (intention.magnitude < 0.5f)
        {
            return Vector3.zero;
        }
        Debug.Log(intention.normalized);
        transform.position += intention.normalized * speed;

        // Ignore this for now
        return intention.normalized;
    }```
warped idol
#

@wary ledge So what is your logic looking like at this point?

#

I figured you made changes after talking to Game Endeavor

wary ledge
warped idol
#

Cool. Yea I was messing around with shaping but nothing really worked yet lol

wary ledge
fallen nest
warped idol
#

looks like your direction vector might be backwards

#

try switching the tp & targetPos in your GetDirection call

wary ledge
#

^ what he said. Lol

wary ledge
#

Ignore the shitty quality gif.

wary ledge
#

Last one, negative vectors working with it.

At this point in time, it's going to be all about tweaking some values here and there but I'm happy with the final product.

Next up for me is a weighted based action system. Afterwards who knows what. But hopefully I'll be able to come up with some ideas.

fast sail
#

How would I modify/make the navmeshagent to only move 8directionally?

wary ledge
#

After spending all day/two on the above, part of me is thinking I might want to go with the other option I had...

#

FML lol

gleaming imp
#

hey I'm bran new to unity and just getting into C# and well I have a small game I'm working on and I cant find a decent tutorial on a 3D ai can somebody here maybe pls help me?

narrow nexus
#

How do I make an object follow the player

gleaming imp
#

Same question here

real sonnet
#

There's A LOT of ways to achieve AI. And I mean it, each and every game on earth could have its own implementation. You could watch dozen of tutorials and pick what applies to your game. As a beginner I would recommend to start with some "beginner scripting AI" course on learn[dot]unity, it's free

civic silo
#

Hello, I'm looking for help with my AI that I'm currently working on.... I'm pretty much a beginner with coding and no idea why its not working, is anyone able to help?

winged relic
civic silo
#

sorry! thank you for letting me know

hollow path
#

Hey, I have a question. I'm tying to make a werewolf ai with navmesh etc, which for now will just chase player. But it teleoprt on random place and just stand among trees and rotate sometimes. Did somebody know what's a probably problem?

final sleet
#

@hollow path are you setting a destination for the werewolf?

#

And have you set the terrain as static and baked the navmesh?

final sleet
#

Is it walking at all or just staying still?

#

Is it going to where the player was or some specific spot like 0,0?
Are you using rootmotion movement or letting the nav controller move the unit?

#

Are you setting the target destination every update or just once?
Is the stopping distance....

#

@hollow path oh! Your radius is WAY too large!

#

That's the radius of the werewolf movement agent. It should be something like 0.5

#

It probably thinks the werewolf is so large that it's already standing on the player.

hollow path
final sleet
#

So it's rotating to face the player, but not moving?

#

Consistently? If you move the player past it turns to follow?

#

Is the terrain using the walkable layer mask? You might want to just set the mask to "everything" until it's working.

hollow path
hollow path
#

Can I just call to you on dc, it will be easier, if u can do that

final sleet
#

@hollow path yeah, this seems specific enough you can message me. I'm happy to video call when I'm at my computer, but I'm in Oz timezone.

hollow path
final sleet
#

I'm around most days from about 11am to midnight. But I check discord between other tasks so I'm unpredictable.
I rarely know when I'm going to get a block of time in front of the computer.

#

Best bet is to DM me, share the project or upload or whatever works best for you so we can do as much as possible without being online together, and if you spot me online poke me and ask if I'm able to take a look :)

drifting holly
#

if i were to hypothetically make a very large collection of NPCs, and i do mean very large, would i be able to use my GPU to process them?

winged relic
hollow path
final sleet
crimson oxide
#

My navmesh agents keep stopping and jitter in place if the target is on an area that's unreachable. The behavior didn't show up until today, and no changes were made to navmesh agents. Any ideas?

alpine glacier
#

Hello everyone, can i get some pointers on AI coding? i've been using statemachine for it, but it seems unnecery in some placeses and completely essential on others. Is there projects and/or videos that you can recommend?

ruby owl
#

how do I make AI cars?

zealous mantle
#

Make a player controlled card, then instead of using player input, use AI input.

fallen nest
ruby owl
#

ok thx

fallen nest
#

Such as the agent going into the obstacle position, which was really weird

#

Instead of the target

fallen nest
#

Never mind I got another way (sort of) working using this method

raw tiger
#

Hello i do a zombie game where on the CIRCLE zombie SPAWN and have to go on the CAMP for kill the player.
So can you suggest to me the best way to do this with MLAgents toolkit ?
I have add invisible wall for create the way to follow to the camp.
but i need to priority to attack the player when he are in good distance of him.

mighty glacier
#

Hi, I am building a turn based 3D shooter game and wanted to design an AI where enemy soldiers can move to a position where they have line of sight to one of the player's soldiers so that they can shoot them.

I set up unity's navigation mesh and can get the enemy soldiers to move close to the the player's soldier(s) during their turn but I was wondering what the best way to implement getting them to a position where they are able to shoot the player's unit. The nodes in the navmesh are pretty sparse, I was thinking of creating additional nodes inbetween the unity navmesh nodes and testing line of sight at each node before getting the unit to move to a node that is a) close to their position and b) able to see the player's unit from that node.

My questions are: 1) Is there a way to place additional nodes between generated nodes within the unity navmesh so I can reuse the built in pathfinding for shortest path? 2) Am I approaching this the wrong way, is there a more flexible way of achieving the above without the sparse granularity of using nodes to determine positions where the enemy units can move to?

sharp mulch
crimson oxide
polar compass
#

Any idea what would cause this to happen in the baking?

#

(The building also seem to be entirely ignored)

untold helm
#

It's not easy for training mlagent, it takes me about 2 months.
And some glitch are not sure if it is relate with checkpoint?

alpine glacier
#

So i have this enemy ai

#

And i want it to point towards the player

#

But every time i try it off by alot of degrees

#

Ive used lookto rotate and various ovr methods

analog goblet
#

I have a bit of advice I'd like to share with you guys about Unity 2D's composite colliders and the A Star pathfinding system:

I have recently discovered that when using the A Star pathfinding system in the Unity game engine along with any 2d colliders combined into a composite collider, the navmesh resulting from generating a scan from A Star has many errors and missed/mistaken areas that should or should not be walkable. To fix this problem, I have found that changing the composite collider's geometry type to polygons instead of outline patches up these mistakes reliably.

Of course, this will not do anything if your main A Star script has its circle collider diameter set too big to generate any meaningful pathways throughout your tilemap but I have provided the solution for any people who have done this correctly and are stuck. Hope this helps!

half sigil
#

Whenever my enemy gets hit by a bullet and it pushed back, it's pathfinding breaks. Any help appreciated.

torpid stump
half sigil
#

I have a 2D Top down game and I use A* pathfinding

twilit saddle
wild shell
#

why is the navmesh bake button cant be clicked at all

severe fable
wild shell
#

somehow I just fixed it, I make the objects static

#

idk I did it before and it wont work

severe fable
#

It's deffo important that all navigable surfaces are Navigation Static

wild shell
#

yeah I did it before but not working but now working. idk lol

slow plinth
#

Love this channel

#

Only questions

raw tiger
#

😒

hazy oar
#

This is not a neural network or anything, its a minimax algorithm.
I am trying to make a AI that plays checkers with different "strategies" which right now is just best and worst.
The problem is, Player 2 always seems to loose. They sometimes seemingly randomly make a terrible move, letting Player 1 capture pieces for free for seemingly no reason. I always run it at depth 6 or more so the issue is not that it doesn't see it. Perhaps it could be an issue with the Alpha-Beta pruning, or maybe I use the wrong variable somewehere.
https://pastebin.com/XugNKNGt
The issue is in the Search() function. The ApplyStrategyPart modifies numbers so if I want it to pick the worst strategy, I can invert the score the AI gets, and other stuff.

#

Huh, if I remove just one piece Player 1 suddenly looses quickly. Now, that would suggest that it is working fine, and it is just an advantage from starting first, but when it was balanced the mistakes it made were easily avoidable, and it even recognised that it was loosing right after the move as once the oponent moves the evaluation goes down a lot (for them).

sinful belfry
#

Could I pick everyone's brain with a Unity programming task I'm trying to accomplish? It's not related to a dev test or any kind of employment thing, so no rush.
I'm trying to get vehicle AI to follow targets around a track.
Once it collides with a target, I want the script to go to the next target.
Should I put my target objects into an Array, and just have a function get the next object from the array? My C# is a little rusty, but if the function gets to the end of an array, it should circle back around to the first item, right?
My end goal is to have the vehicle AI go from target to target until it does a lap, and then do it all again until told to stop (IE the race ends).
Any suggestions on how to approach this would be much appreciated. I see like a dozen different ways to do vehicle AI, but I felt like a target-to-target system would be flexible for any track ideas I had, especially if I want a more open world approach.

stone owl
#

_
__
Detecting if agent's current path to destination is in a straight line, how would I do that exactly?

real sonnet
#

I'd try with the cross product

hybrid hamlet
#

Is there a guide to writing a good AI? All I have is a navmesh agent, types of environment props (hide, climb, throw) and aiming while shooting. It feels to basic

hybrid hamlet
#

Lol

#

There are no scopes

#

So I guess that'll be easy

modern orbit
#

Hello! I wanted to make an HP Bar for AI but my problem is that when I either get behind or beside the AI the HP Bar (Slider) isn't facing me. I want it to be facing towards the camera so I'd know how big their HP is without having to go to their front.

#

Please feel free to ping me if someone's going to answer me.

stone owl
#

an AI that can deal with (or pretend to in most cases) a player's dynamic decisions, all the unpredictable choices in movement they make is a lot of fun

#

eg we can hide if we see a player at a distance and we have no ammo, but what if the player runs full speed at the AI? hiding would seem silly since the player is running with it, instead maybe do a shove, roll to the side etc

tawdry cairn
#

Is it possible to implement 2d pathfinding system with no grid?

noble fog
#

A* pathfinding for example node based. Nodes could be anything, they can be grid, voronoi, etc.

hybrid hamlet
#

It's one of three rare and random behaviors. The other two are cowaring away and dancing. Just to spice it up. πŸ˜„

tawdry cairn
#

That is, for A* implementation, I have to divide the map into certain areas, like nodes?

noble fog
#

yep

tawdry cairn
#

Many thanks

stone owl
#

always nice to have surprises

hybrid hamlet
#

Speaking of A*, what does the F cost stand for? I can't find a clear answer.

#

I get that the H stands for Heuristic. The G.. Actually I also want to know what the G stands for lol

real sonnet
#

F is a math standard notation to express a result (here the cost) as a Function of smthg else (here a node)

#

then G is used because well, F is already taken, so you just increment in alphabetical order :p

#

Then H is used for the same reason G is already taken.

#

Nothing to do with A*

stuck scaffold
#

hi i am making a tps game i have a ai that shoots when the player is in range and also moves to different points but my game is tps so i need it to hide take cover run behind run ahead etc can someone help me with a basic code or any youtube tutorial

rustic vortex
#

Try looking up "AI State Machine" in google and/or youtube @stuck scaffold

crimson oxide
#

When using the Unity Navmesh, if a target is above the pursuer, the pursuer goes to his xz location, but doesn't actually try to use nearby offmeshlinks to try and get up to the higher area. Is there a way I can fix this?

hybrid hamlet
#

Or the H was there first and F and G got added after :p

sinful belfry
#

So several days ago, I asked about a vehicle AI system using way-points. I had a few people graciously help me, and I actually got a very rudimentary vehicle AI system working. However, this presented some flaws. The point-to-point method combined with my physics based vehicle controller turned into a sloppy mess. My boat will launch past points due to its speed, over compensate in turns, and jerk violently towards the next transform point.
I see a ton of tutorials that implement a bezier curve for objects, but I'm stumped on how to make an object follow the curve using physics forces, rather than transforms. Example: Have my boat object apply a negative or positive torque force to turn onto the curved bezier path. Secondly, have it accelerate or brake to stay on the path at a good pace.
I know the information exists somewhere on how to do it, I just need to find the right tutorial haha.

maiden dust
#

is there like a base enemy ai for fps games that unity provides?

sinful belfry
maiden dust
#

ok thx

winged relic
# sinful belfry So several days ago, I asked about a vehicle AI system using way-points. I had a...

I'd suggest increasing the distance from the waypoint which triggers next waypoint selection, you also need to manage speed if making a turn. Simplest is to either slow down based on distance to waypoint or have it as a parameter of your waypoint which the boat can use. I did this for a very simple demo I was making, but if you want something more inteligent then may need to do some research.
You could for example, where you have bends the waypoints are closer together look a few waypoints ahead and use some decision making based on distance between points. If they are closer together slow down, just spit-balling here as I didn't have to go deeper for my demo.
there are a few articles on handling vehicles in the following Link which should help give some more ideas

mellow rampart
#

Howdy, I want to create a basic AI enemy for a VR fps game and am completely ignorant on coding. Are there any Unity assets you would suggest I download?

alpine glacier
dusk meadow
dusk meadow
#

I found my problem! I had frozen the z axis, but enabled rotation in the A* script. Disabling rotation in the a* script fixed it πŸ™‚

weak gull
#

i stumbled across this forum post. Is turning nav mesh agent off n using created path more performant?

#

The post is from 2017... so I'm not sure if anything has changed with the api since then

molten sequoia
#

@weak gull If you don't need the agent, you might be able to just do navmesh queries without it

golden kettle
#

Hello again, so ive been doing bits on and off with my utility AI style system and its been going ok, but im struggling to find a nice way to represent the damage or useful application of a skill/ability.

So for example I have an ability attack which does weaponDamage to 1 enemy, however I also have cleave which does weaponDamage*0.6f to 1 enemy AND any enemies on either side.

So currently my utility scorer looks at the potential damage output, which attack would always score higher, but if there was 2-3 enemies in a line cleave would score higher, but its a contextual utility, so does anyone have any advise on how to best express this, as it seems like its too complicated to just expose as a single utility value.

golden kettle
#

Hmm think I will add some sort of runtime modifiers where it has a predicate and a bonus and if predicate is met it applies a bonus to the consideration or something

gloomy storm
#

Does anyone know a good way to implement an inference engine in my project? Not for machine learning like the Unity Inference Engine, but just a forward-chaining rule-based system?

golden kettle
#

sounds a bit like GOAP

#

where its just actions linking to other actions and if you are at A and you need to go to D you may have A->B->C->D or A->C->D (latter would win)

fleet crown
#

I've made a basic AI, however, it is incredibly buggy and I have no idea how to fix it

code: https://pastebin.com/10BX5Vxp

#

the buggyness has mostly to do with handling slopes

verbal gust
#

Hello! I'm not sure if this is the best place to ask about a NavMesh issue, but here goes--

I'm using the NavMeshSurface component on an object rotated 90Β° to make a wall. I've placed a NavMeshAgent on the wall with a basic wandering AI to move it to random points on the wall.

After a short time, the NavMeshAgent will begin to stutter, eventually stopping. If I manually force it to move by dragging it in the Scene view, it "resets" and continues moving normally for a bit longer.

I tested it on my ground, and it worked perfectly, so there's something different about the wall. I don't have any Rigidbodies, so physics shouldn't be what's causing the issue. It's not a framerate issue--another effect is working perfectly in the Game preview (not visible in the attached video).

I've tried adjusting the Voxel Size and Tile Size, with no noticeable difference. Turning the Agent's collider on and off made no difference.

Any help would be appreciated, and please let me know if you need any additional information. (In addition, if anyone does respond to this, please ping me, I might not see your reply otherwise).

Object components, for reference: https://imgur.com/a/8lBNHFS

zinc zenith
#

if it has a rigidbody

fleet crown
zinc zenith
#

check in brackeys fps tutorial

#

@fleet crown

fleet crown
#

Ill try that later once sourcetree is done its 20 hour commit sequence

#

Its taking its time

mellow rampart
alpine glacier
#

@mellow rampart no.

#

If you type either name into the asset store you get the exact assets I talked about...

brazen stump
#

how would I go about pathfinding on a NON grid based 2D game

#

side scrolling, not top down

#

as far as i'm aware the navmesh system only works in 3D

#

and my levels aren't (and can't be) grid based

noble fog
#

Just basic A* implementation would work, with trigger events on the way to jump up or down.

brazen stump
#

I thought A* only worked on grid based levels

#

how could you make A* work without a grid

noble fog
#

Any nodes. Platforms can be presented as nodes

light saffron
#

do you guys know a way to batch queries to the navmesh? I need to verify that targets are reachable, in great number

dense sparrow
#

by Way i mean a Point or P if u will

versed sand
#

A*, floor is marked red.
it has a tile collider but otherwise the player and enemies will fall to through the ground.
how do i solve this?

dense sparrow
#

You could access them all at once with a forEach function on the List.

#

So , ignoring my syntax mistakes it would be like this :

UpdateList()
{
  forEach ( var point in Points) 
    if (is_distanced(point)) Points.remove(point);
}```
#

Or if u want a one liner you would do
Points.foreach((p) => { if(is_distanced(p) Points.remove(p); } );

#

And u may call the UpdateList every N seconds depending on how cpu intensive it would be. If you have a dozen of points I suggest N be 0.2 , if hundreds, N be 1.3 or something. If much more than that, you can go for an asynchronous method which yields after each M checks . M could be big

wanton silo
#

If I want to create an AI with some abilities based on player distance, time or health left. Wich is the easiest way? Ienumerator, stateMachine or i'm missing any easier way?

light saffron
wanton silo
#

@light saffron My bad! i'm doing a 2d Boss

#

i'm trying with this:

light saffron
#

tangible: tell us what you want the things to do as the various agents react

wanton silo
#

oh, I dont know if you mean this: I want an Idle animation, if the "player" its too far away, walks towards him and attack him, if he's near a corner of the room, change the normal attack to a special corner attack. and 2 or 3 "special attacks" choosen by time (for example if the player is out of range for 3s or more and the health is behind 75%) and if that conditions are met, choose from one special or another by random.

light saffron
#

see how you describe your scenario with simple linear "IF"? and then you get into a state which limits the number of options? that's State Machine

#

special attack with 75% condition to another state

#

so yeah you got this

wanton silo
#

so using animation attached to StateMachine is the way to go?

light saffron
#

I wouldn't use anything mecanim

#

maybe try the Unity integration of bolt, its FSM might be easier to use and performant enough, although I read that on 2021.x using bolt incurs massive slowdown on playback and domain reload

#

I made my own FSM, it's so easy to make

wanton silo
#

I'll check what's a FSM and what's a bolt and what can I do with that, thank you @light saffron

dense sparrow
dense sparrow
zealous mantle
#

Start by defining what an enemy and what it should do.

#

Without knowing how you want your enemy to act, you're not going to be able to build anything.

real sonnet
#

try to google things like "patrol AI" or smthg like that, will give you ideas

#

there's a lot of different ways to do it

#

depending on your game

#

or "guard AI" maybe

versed sand
#

i have a problem with a*

i wish to have a tileset dedicated to the ground with a collider, problem is that would make it unwalkable in the red and blue squares. any solution?

ripe gorge
#

Im was trying to build a scene from scratch in the FPS shooter template but when i place the enemy and bake the ground in the navigatie tab the ai will follow me when he "sees" me but he doesnt walk around if he hasnt seen me

#

than he just stands there

ripe gorge
#

not even moving a it

woven copper
#

Hi, I'm making a kind of 2.5D game with 8-directional movement, and I'm trying to figure out how to restrict a NavMesh AI to those 8 degrees. Any advice?

real light
#

Anybody use NPBehave before?

plucky dragon
#

Is there a way to ignore painted "trees" on terrain when baking NavMesh?

alpine glacier
#

Err pal u could maybe bake navmesh before you paint

#

Delete grass,trees etc and bake it

#

then begin painting

#

make sure to back up tho

brazen stump
#

in the AStarPathfindingProject, is there a way to get the pathfinding to account for enemy height in 2D

#

currently this flying enemy will try to reach the player but get caught on platforms because it doesn't account for the enemy height

keen crater
#

anyone using Aron Granberg's A* solution for creating navmesh at runtime? wondering how it compares against Unity's Navmesh Components

stone owl
#

Aron's take that is

keen crater
#

just wish I could test it properly before dropping $100 on it

stone owl
#

Is there not a demo? Feel like there was maybe I'm confusing it

keen crater
#

yeah there's a free version and it contains a lot of stuff but not the runtime navmesh generation that I'm after

stone owl
#

Anyway you'll not find a better one I'll tell you that much. Hes been praised for a while for his work

#

Well worth the price if you need it

#

Investment you can take to any project really if it has ai involved, very flexible

#

..more performant, etc

keen crater
#

yeah for sure

pseudo crow
#

Hi all, I'm having some issues with Emerald AI and it telling me my gameobject is not an active agent, despite my navmesh being baked and a navmesh agent component being attached to the gameobject.
Would anybody be able to help me diagnose the issue?

unborn olive
#

Hi !
I have 2 problems concerning my FSM for my AI and I don't know if it's an issue inherent of the pattern itself. It's about transitions, and the fact that they are hardcoded in the states themselves. That mean that if I make a Patrol state, I usually add a transition that goes to a Chase state if my AI see my player, pretty basic for a melee enemy. Now if I want another AI that shoots when it sees the player during a Patrol without going through a Chase... well I'm kinda stuck. And it's just one example. I could make a quick fix and dirty fix but that won't work for all my cases.
I basically have to make a PatrolChase and a PatrolRanged, which seems very... not okay. I can get the running code out of the state itself and create an Action class and put my patrol code in a PatrolAction, but I'll still need 2 Patrol state that both use the PatrolAction but have a different transition.

My second problem is concerning attributes. Where should I put attributes that only interests some AI but that I need to be able to change from the Inspector ? I have a "brain" component that runs my FSM and serves as a "blackboard", an interface to the scene for my AI, but it's generic, and if I inherit from it, my States wont be generic anymore (since they need a generic brain). In my example, my chaser needs a ChaseDistance and my ranged AI needs a cooldown between attacks (it goes back to patrol while cooling down). If I put both in my brain or my "stat" class that my brain also has access too, I'll end up with a lot of useless attributes on both AI.

Maybe I am overthinking this ? Or is the FSM not adapted ?

final sleet
#

For the second problem the answer will depend on your design and how you like to write code. You might even have multiple places to store the information.

#

I'd suggest using scriptable objects to help with both issues.

#

Imagine having a scriptable object AIData with some method like GetValue("ChaseDistance"), then you can have a PatrolData class that inherits from it and let's you enter the right fields.
Or if you don't want multiple classes just have a dictionary of key, value. Then you can store anything for any AI.
You might need a separate method and dictionary for each variable type.

#

And throw an error if you ask for a variable that isn't set yet to catch any typos.

#

To solve the first problem, split your FSM into different tasks. You have the state, you have the state's it can transition to, and you have the trigger to transition.
A state will have one or more states to transition to, and each of those will have one or more trigger to make it do the transition.

#

So now you can build an interface for a state, trigger and transition. You can have a scriptable object for each, and the AI can have a state as a public variable.

#

So you can have a PatrolState class with all the specialised code. You can then make multiple objects with different settings, for example if you have waypoints it would follow, otherwise it would walk to random points. You could have speed, how alert they are etc.
That lets you have multiple behaviours. A guard with a patrol route. An enemy that spotted the player and is searching. A character that panics while looking for their child. A grazing animal. Just drag and drop the right one onto your characters.

#

Then you need a way to set different states to transition to. So guard might transition to chase or attack or flee.
You could store the list in that units AIData maybe. So the guard transitions to chase. The guard with the rifle transitions to attack. The deer transitions to flee.

#

For the triggers, same thing. Code up scriptable objects and drag them to the transition. So "spot player" or "hears distraction event" or "value is less than" and so on.
So you can then add "spots player" trigger to the "attack" transition and now you have an "attack the player if you see them" behaviour.

#

Put that as a transition from the patrol state and you have guards.
Put it as a transition from the idle state on the guy at the tavern that the player owes money to and you have a loan shark and a challenge for the player to get through the crowded room without getting spotted or drawing attention.

#

I'd suggest not including combat in the AI.

#

Just have an "attack" state, which can trigger your combat class. Let the AI know it's attacking but nothing else. Combat class can then decide where to move or if it should shoot. Splits the complexity into smaller pieces.

#

And allows different attacks. A horse attacking might kick the player and knock them over rather than using the normal combat system.

#

And... That's about it. There's more you can do, but you'd tailor it based on your specific game.

unborn olive
final sleet
#

Yeah, my suggestion is using similar techniques to that.
I started by copying that technique to make sure I understood it well, then designed my own solution that can expand better and give me more ways to mix and match to get more behaviours from the same amount of coding work.

#

But if you start with what they're doing you can update and change the AI if you need more flexibility.
There's no need to split it into as many parts as I did if something simpler will work!

#

In fact, I don't! I always start simple. Each state might be a scriptable object and might even hard code when it changes to another state.
Then I add the more complex stuff only when I need it - keeps things simple for as long as possible, and gets it working really fast so you can move on to the next job, and come back to keep improving it later.

#

And yes, each state should also be a scriptable object. Makes it easier to see what state the AI is in and store data about it.

unborn olive
#

Ok ok I see, thank you for your time ! Also, as a side question, how do handle combat, and especially combat animations ? I tend to use animation events a lot to spawn projectiles and activate collider for melee weapons on the exact frame of the animation, but I wonder how other people handle it. Using hardcoded timer to know how far you are in your animation clip ? Another solution ?

unborn olive
#

This question extends to any state where I want to wait that the animation is completed. For example a monster spawning that would go into a SpawnState, play the animation and start its behaviour once the animation is completed. Again, I handle it by waiting an animation event that tells my FSM "ok I finished you can resume your logic". But it seems prone to errors...

crimson oxide
#

Has anyone run into the problem where a NavMeshHit normal always returns as a vector 3 zero?

slim crest
#

@unborn olive there is a course on unity learn about Β«goal oriented action plansΒ» that teaches how to set up a flexible ai. maybe you can find something useful in threr. Search for goap

unborn olive
#

Yes i'm following the whole course

#

It covers FSM, goap and behaviour trees. I find FSM very easy to understand but I might have a wrong idea about goap and trees as "over complicated" patterns. Definitly gonna look into those

fast sail
#

How could i make the navmeshagent only move 8-directionally and not freeform like it does by default?

light saffron
#

people usually write their own A* pathing or maybe aaron's astar project has modifiers that will give you this behavior

earnest forge
#

calculate the path to where you want to go and split the path into 2 @fast sail

real light
#

Is there any free waypoint editors available and if so where can i find one?

turbid panther
#

hey guys
I have a question on Unity's path finding:
When I set a destination for an agent that cannot be reached, it is able to calculate a path to the closest reachable point
But when I call NavMeshAgent.CalculatePath to the same destination it always fails with InvalidPath status and never returns a partial path
Is there some gotcha I'm not aware of ? Can you make CalculatePath find paths like SetDestination does ?

molten sequoia
#

@turbid panther There might be some heuristic when SetDestination is used. My guess would be that they use the method that snaps to nearest point on navmesh with a small radius and if that doesn't work, they raycast down and try again.

charred token
noble fog
#

Agents have their own (size) parameters you need to set. They ignore actual colliders because dynamic physics is not used.

turbid panther
charred token
#

The only thing I see relating to size is in "Obstacle Avoidance"

charred token
#

Oh i had the quality set to "none" for some reason

#

thanks

#

@noble fog can I make it so that it avoids some things but not others?

noble fog
#

Don't remember, should be in documentation.

charred token
crisp quartz
#

hey all, what is the best way to move a navmeshagent onto a new nav mesh? I tried warp but it seems to get stuck on the last one it was on (basically I load a new prefab room in with its own nav mesh and want to just reposition the character on to that.

crisp quartz
#

ah I think I solved it, i seem to have no navmesh in my prefab - can I not bake a navmesh into a prefab?

crisp comet
#

Hi guys, im brand new to unity, ive got this isometric view of player,managed to make him move and now i want to create an enemy to push him off the platform. I know how to create an enemy that will detect the player and follow him so I just need some help on how I would go about coding a script to tell the enemy to push player off platform?

dire basalt
#

Sorry WildRover, I do not know the best way to approach that.

Our Level Designer recently came into a problem with NavMesh in that it did not connect multiple areas on flat terrain (as shown in the image). From what I see from the scene, NavMesh is having problems with generating connections over overlapping meshes. It creates one area on the first mesh, one on the overlap and one on the other mesh, but doesn't connect these areas even though together they form a flat terrain. Do any of you know how we can combine these areas into one big surface as it should be?

real light
#

How would you guyd handle traffic light systems for cars and peds i usually see people use colliders/triggers im not sure if there are other methods

alpine glacier
#

how do I make enemy ai shoot player?

fossil orbit
fossil orbit
tawdry fog
#

is there a navmesh function for rotating only the 'head' part of an animal to face the player?

#

but only clamped within certain feasible regions to prevent it from bugging out and having a broken neck

real sonnet
#

That's not really a navmesh-suited problem

#

You can write a little script to have the head track and lookAt the player

#

I'm sure you can find plenty tutorials on that from YouTube for example

alpine glacier
zealous mantle
#

Enemy sees player. Enemy shoots bullet in player's direction.

crisp quartz
#

hey all, is there a way I can force a navmeshagent not to cut corners? and take the full turn

#

lazy navmeshagent

atomic spruce
#

how can I set a condition between these elements/array?
that if an object is particularly occupying a waypoint the others will stay put until the next waypoint is unoccupied

#

base on the script

crisp quartz
clever flame
lament rapids
#

is there a free ai app that I can use for more then a week? everything I see in the app store is $50 or free for 1 week then you must pay so how can I actually use unity for free is I must have an ai app to use it and there is not one for free? 😦

kind sedge
lament rapids
#

thanks πŸ˜„ thats what i need

crisp quartz
#

he yall im struggling to pull out these edges more on my nav mesh, what setting should I alter? (basically want more space between navable mesh and wall - thanks

#

ah it was my agent radius I think, it just wasnt updating properly

crisp quartz
#

can you have tigher edges around the outside but more gap inside?

kind sedge
#

atm my enemys can go through eachother if they have rotation disabled

#

they like to stack up

#

nvm rotation doesnt affect it

weak moon
#

How come when I load a scene all other scene's navmeshes are shown?

#

Is there any way I can just see the navmesh for that particular scene?

crimson oxide
weak moon
crimson oxide
#

That is odd behavior. As far as I'm aware, when you load up a new scene, things from other scenes shouldn't be loaded up unless they have Don't Destroy On Load, but that's from loading through script

weak moon
#

Yeah I don't know why it's doing it

#

The navmesh out there is from my TestScene I was building the gameplay in

crimson oxide
#

Have you tried clearing the navmesh and then rebuilding it?

rancid brook
#

hey im encountering some issues with navmeshagent i know knothing about ai and i followed a tutorial from brackys. The tutorial was about an rpg game and ep10 was called ai so didnt watch ep 1-9 i made a nav mesh agent but there wasw no nav mesh so i watched ep1 and brackys made a nav mesh now when i write in the script NavMeshAgent agent; the word agent becomes darker, which mean the it cant find the navmesh agent?

#

here is my code

#

and the instanse

weak moon
rancid brook
#

pls help me

#

im confused

weak moon
rancid brook
#

i have added it

#

and tried removing it and readding it

#

3 times

weak moon
#

@rancid brook You're not using the agent variable in the code

#

You're just getting the component

rancid brook
#

agent is a variable?

weak moon
#

You use it in your code as any other variable

rancid brook
#

ok so i change what exactly

weak moon
#

Depends what you want your NavMeshAgent to do

rancid brook
#

ok

weak moon
#

This for example sets its destination

rancid brook
#

thx a lot

#

ill try it

#

lol i hadnt save the code

#

🀣

#

its working!!!!!

#

πŸ˜€

weak moon
#

@crimson oxide I found the culprit. I checked this little rascal and cleared the navmeshes and then baked again.

rose pebble
#

Yo, does anyone know how to make ranged navmesh agents fan out and attack ala starcraft?

Like surround the enemy instead of trying to fit through

alpine glacier
#

hey guys I wanted make an npc that is killable, but whenever i kill him this console shows up:

#

he has a nav mesh agent

#

also this is the technique im using to kill him

#

basically he turns into a ragdoll and navmesh agent is disabled

#

but i keep getting this error

#

btw im doing this for a gamejam so any help is appreciated

fiery geode
fiery geode
pure oriole
#

Hey, I'm creating a procedural world made up of chunks, and I'm creating nav meshes on each chunk during runtime.
When the two chunks are loaded next two each other, the seems look to be connected, but my AI still can't pass to the other nav mesh.
For each nav mesh, I'm using NavMesh.AddNavMeshData(m_NavMesh); and passing in my chunk's nav mesh data, but maybe that's not enough?

The red line shows the border between the two chunks, and the red circle on the right is the agent's destination, but there's "no path".

atomic spruce
#

I have this patrol script[https://gdl.space/amujepunek.cs] which moves an object in a fixed path of waypoints, I wanted to figure out how to disable the movement of the objects that are recently spawned if the current waypoint is occupied by an object.

#

Ive added some codes (starts at line 114) but I find it really confusing since im new to C#. any tips?

finite trellis
#

Does anyone know of any good resources (open source libraries, tutorials/courses, even cheap paid assets) or suggestions for AI movement patterns? -- Beyond just basic avoidance of obstacles and chase. Things like hiding, circling, formations, and just having a generally interesting / dynamic movement pattern when - in my case - shooting at the player? I'm currently using A* Pathfinding but beyond just getting from point a to point b in an efficient manner I'm a little hung up.

supple rock
#

Sorry to interrupt but I have a short question. I have this map (green terrain), this water (blue, no collider), and the gray plane which is invisible at runtime.
The goal is to make it so terrain above the gray plane is walkable, and below isn't I've tried using modifier, modifier volume and obstacle and none of them work. The walkable terrain ends up below the gray plane not above. Any way to fix this?

#

Not the intended result

crisp quartz
#

hey all how can I stop the navmesh generating like this - looks broken/wonky

noble fog
#

Could probably add an invisible collider as a railing along the steps.

fast sail
#

if those are steps meant to be walked up, that looks correct. if it's not, adjust your step height

#

in the agent settings

true lava
#

Hey guys, is there a way to have a NavMeshAgent not attempt to move towards the path? I'm trying to make a physics vehicle take on the Agent's info and navigate through it instead of having the agent move itself

true lava
#

I have already tried just forming a path and storing that (no Agent involved), but the thing is too strict. if the source or destinations are high off the navmesh, they don't find a path below

timid wigeon
#

I'm trying to "find the point with the shortest path including obstacle avoidance" and Google is saying I can calculate the path and then use NavMeshAgent.remainingDistance but doesn't that mean I have to assign the path to the Agent and can't really just compare 3 different points and their paths?

swift roost
#

is there any way of setting a NavMeshAgent in code by finding a GameObject with the script?

timid wigeon
#

You might not want to do that because that sounds super costly, but yes you can

gaunt geode
sharp pollen
#

does A* pathfinding have to involve diagonal movement?

zealous mantle
#

Nope

gaunt geode
supple rock
#

Ahh

#

Thank you, gonna try this

fringe raft
#

Hi Folks, is it possible to calculate a NavMeshPath using an editor script? I keep getting: - "CalculatePolygonPath" can only be called on an active agent that has been placed on a NavMesh. when trying

#

I suspect it is because I'm in Edit mode, but would be nice to run it in Editor mode to tweak what I'm doing

keen wigeon
#

Hello! I'm trying to make a patrolling ai, I "stole" the code from a video. I'm having problems at rotating it...

 if (currentWaypoint < waypoint.Length)
        {
            Vector3 target = waypoint[currentWaypoint].position;
            target.y = self.transform.position.y;
            Vector3 moveDirection = target - self.transform.position;
            if (moveDirection.magnitude < 3)
            {
                currentWaypoint++;
            }
            else
            {
                transform.rotation = Quaternion.LookRotation(moveDirection, Vector3.up);
                controller.Move(moveDirection * speed * Time.deltaTime);
            }
        }
        else
        {
            if (loop)
            {
                currentWaypoint = 0;
            }
        }

All variables are defined, no errors. Just the rotation looking off.

#

(I need help asap it is 00:12 rn)

alpine glacier
#

I don't think its AI problem

keen wigeon
#

oh sorry

tribal marten
#

I'm having a really odd problem

#

The NPC in editor view is placed at a certain position, but when I go into Play Mode, they spawn in a completely different position, but it's the same every time

#

and I can't even move them during play mode in scene view

#

ignore this, I just didn't do my due diligence with animations and it's fixed now

clever flame
#

Does anybody wanna help me figure out why my agents refuse to move?

#

Like does an agent always need to do a Ray/Raycasthit check just to move or nah?

fiery geode
clever flame
fiery geode
clever flame
fiery geode
#

I see that the Patrol Points list is empty. Was this already the case?

clever flame
#

Patrol points only get populated when the function is called, in essence it goes as follows

#

called when patrol button is clicked

#

inputmanager checks on update and if patrolfunction is true it starts the Patrol method setup

#

Patrol method grabs all selectedUnits to pass the 2 Vector3 params to their single entity execution

#

until finally the array is populated by setting empty child objects with the required positions (1 where the unit is currently at and the other where the mouse was clicked in InputManager)

#

Then in the unitObject update it checks if patrol is true and if so its supposed to execute the UnitObject Patrol method

fiery geode
#

Why does the MonoBehaviour class UnitObject also have a parameterless Patrol() method? And what does that do? Does UnitObject derive from BehaviorFunctions?

fiery geode
clever flame
#

Objectclass in just a reference from inside the InputManager to call and interact with individual entities holding the UnitObject script

#

And nothing really derives from BehaviourFunctions since its a seperate class thats supposed to exeute specific button action logic

fiery geode
#

Ok, I see

clever flame
#

I understand it might be confusing with 2 methods called Patrol, 1 is in the inputmanager script where the user configs the selected entities and the other is the single entity making attempts to move

fiery geode
#

That is indeed a bit confusing

clever flame
#

so any idea why the agents arent moving?

fringe crag
#

Hey all, Does NavMesh.CalculatePath() not work with the component based NavMeshSurfaces? I've tried both navmesh.calculatepath and navmeshagent.calculatepath and they return false. If i swap over to the standard navmesh system it returns true. Anyone have any insight?

fringe crag
#

@clever flame have you tried manually entering a known valid position in your set destination as a test instead of grabbing from your patrol points

tame crag
#

Hey does anyone here know of any Advanced Enemy AI tutorials out there? The ones im finding on youtube dont seem to explain something like an enemy Cover System and such just Idle and Shoot

molten sequoia
#

You are more likely to find better resources if you split things up. Trying to search for a complete AI solution that also has a solid cover implementation is a lot less likely to yield results than searching for a general AI design and then looking up approaches for (AI) cover systems.

timid wigeon
# tame crag Hey does anyone here know of any Advanced Enemy AI tutorials out there? The ones...

The easiest implementation of "cover" I've seen only works for "low cover". They usually put the objects either on a separate layer or cache a list of all the objects. Each piece of cover will provide a "safe spot" or "safe zone" that is on whatever edge is facing away from the player, so basically it's whatever the center position is of the cover piece + (a Vector with the same direction as from the player to the cover center).normalized * magnitude related to radius /thickness of the cover.

#

Side cover, however, is a whole other beast I've been tackling for a couple weeks

#

@tame crag I'm about here

smoky jasper
#

anyone here ?

alpine glacier
#

Does anyone know what could be the problem here?

I'm very very new to AI, so it may be obvious.

I wrote a script that simply tells the AI to go from one point to another, I baked the area and it all looks fine but for some reason the AI won't go up or down stairs no matter what.

#

I've messed around with the Agent/Bake settings to try fix this, but nothing has worked

quaint gazelle
#

@alpine glacier hmm, have u tried voxel size

#

@alpine glacier

sinful mist
#

Im creating a npc AI thats moves when im not looking and stops moving when looking, is there any method or other thing that i can use to know if im looking or not to the npc AI? it works simular to scp 173
or do i need to put a manual trigger on the camera?

fringe crag
#

Vector3.Dot product will take 2 forward vectors and give you a number between 1 and -1 whether or not they are facing each other

#

and if they are you can do a ray cast to see if there's a wall in the way

#

@sinful mist

blazing pilot
#

I'm new to game making, any tips on pros and cons of using NavMesh vs. a* for pathfinding? Are they suited for different things? Right now I'm making a 2d game

tardy junco
blazing pilot
safe basalt
#

the direction.y doesnt work

#

the chasing doesnt always work

#

and i only wants him to attack the player not the walls and object when it enters the trigger

modern orbit
#

hello

#

i just want to ask where i can find a reference for making a code where the code detects if all of the prefabs are gone

#

like some sort of a victory mode

alpine glacier
#

does anyone know if its fine to leave the markup list blank when using NavMeshBuilder.CollectSources() ?

#

well empty

hot siren
#

Is there a way to make the AI ignore a large block (ground below the river) but not the underwater zones? Images to follow

#

I got a giant obstacle that clears all navmesh underwater, but I'd like to not have to make a trillion of those to cover all underwater without covering the underwater baths

wary ledge
#

Anyone have any recommendations of topdown / isometric AI? I'm leaning towards the style of like, Enter the Gungeon I suppose.

#

Specifically, tutorials of how to handle different attacks I suppose.

near tusk
#

hm

#

i am trying to implement auto-run on my player; the player is using click-to-move. ray cast to a point on the terrain and set that point as the destination. simple.

I am really struggling to get the character to keep moving forward at a constant rate. The closest I have come is the following, but it fails when terrain is not flat or if there are obstacles; the player bumps around, changes direction, or stops in those cases. Once I hit an invalid patch of the navmesh it stops working. This makes sense, but what I am really trying to do is just keep the player plowing forward no matter what and never changing direction; just like basically every MMORPG that has an auto-run function.

Is there another approach to do this using the navMeshAgent and click-to-move-like movement?

#
{
     playerNavMeshAgent.SetDestination( this.transform.position + this.transform.forward );
}```
fickle ravine
#

but usually you have an invisible object using the pathfinding

#

and your player moving towards its current direction

#

then do instant changes on the agent

#

its very hard to get a nice result with an agent on your visible character

wary ledge
#

Yeah, so back to my question from earlier, I'm trying to figure out the best way to go about AI.

I think I'm over complicating things. But I was tyring to think of a way for each enemy to be Dynamic in the sense of their attacks. I already got movement down, for the most part at least.

But I sort of wanted Grunts (Small guys) to run towards the player, hit, then move out.

I was thinking about doing a weighted system, but honestly at this point I think thats just over complicating it, as at the end of the day I think all I'd need is: Run Towards player, Attack player, back up, repeat.

tardy junco
wary ledge
#

But again, probably over complicating things.

tardy junco
#

weighted grab bag?πŸ€”

#

What prevents you from scaling state machine to boss fights?

wary ledge
tardy junco
#

Both

wary ledge
#

Basically lets say a boss can do like.. 4 Attakcs.

Basic hit the player is weighted at say, 50% of the time.
Super Awesome One Shot Ability of Doom is 10%
FireBall 20%
Ice Storm 20%.

Concept being, you reach into the bag, pull out one of the above, and action it.

tardy junco
wary ledge
#

This was the tutorial I was originally referencing. Well, not tutorial, just the concept.

tardy junco
#

Simplest way would just be a state that decides the next state out of a list for example based on their weights.

#

OR you could modify the whole system to use weights when transiting between states.

wary ledge
#

Yeah, that's sort of what I was thinking Something like:

Chase Player -> In Range of ONE of many Attacks AND Attack is Off Cooldown -> Use Attack -> Otherwise keep chasing.

near tusk
quick zealot
#

I am using a procedural dungeon generator to create random dungeons and I am kinda confused how to create the NavMesh of the level dynamically.

tardy junco
#

Although it seems like they moved it to a package recently.πŸ€”

wary ledge
#

Does this look about right?

#

TBH, I'm 90% winging it as I've made similar before, but never based around AI.

wary ledge
#

Also, better yet... I'm not sure if I should do local avoidance/flocking or not... Currently, I am.

#

But I'm thinking maybe I shouldn't.

tardy junco
#

I'd split it into several classes and avoid putting anything specific in the fsm itself. States would be separate classes with one base(abstract?) And contain all the logic.

tribal bolt
#

Yup, so to dig deeper on that, have one base class that manages the running state. It'll basically constantly call the state that's currently being run, then make a base class for the States, and have all the states inherit or implement an interface from the class.

In the State classes you'll have it do the if conditions, so while you're in that state class and it's doing that state by the end of the function, return the same state to the state manager. However, if your state meets the conditions to change to a different state, then return that state to the state manager instead. Then the state manager will start running that states class conditionals and the loop forever continues

#

This allows you to easily add more states to your code without breaking anything in the process

wary ledge
#

Cool, thanks for the reply's guys. I got a rough idea from what you were saying.

First time coding AI, it's deff something thats for sure.

half heart
#

Any ai tutorials for pedestrians/cars in 2d games

covert jetty
#

Guys, I kindly need your help... I'm trying to use two navmeshes areas for two different agents, but I can't figure it out how to make them work

#

I set the agents physical properties here

#

I'm not sure this was the correct way to use areas

#

unfortunately only the humanoid meshagents work, as I set "FinalBoss" in the Nav Mesh Agent component in a specific prefab, its instances will behave as they are not on a navmesh

#

Do I need the NavMeshSurface from the NavMeshComponents repo?

tall viper
#

Has anyone experience with A* and may help me with enemies not wanting to pathfind outside the screen?

worn sorrel
#

can anyone explain the best way to do a* pathfinding

tall viper
tall viper
#

I could help you with the basics

wary ledge
#

On the topic of State Machines etc.

I got something down pat now. I'd consider it a hell of a lot better then what I had.

However, I'm just wondering what'd be the best way to now going about creating attacks? Obviously I'd want something like: public abstract class Attack : MonoBehaviour {};

But would my best option to be basically, code an "Attack" then attach that Script to the Monster/Whatever. Then from there, have my Attack State/Action call the attack that way?

worn sorrel
tall viper
#

Im actually working on a topdown shooter as well

#

I used the A* Pathfinding project

#

Brackeys once explained it in on of his videos

wary ledge
#

If you're really lazy, theres a good A* Plugin available for free.

worn sorrel
#

i need to code it as im doing a school project

#

ive got the basics done

wary ledge
#

You need to code A* from scratch for a school project?

worn sorrel
#

Yeah

#

like within unity

hot patrol
#

Honestly there’s so many resources about a* creating one on your own is not very hard…

fickle ravine
#

even got special points like jump points going

covert jetty
quick zealot
finite trellis
#

Anyone know: Do NavMesh agents move via transform.translate?

still minnow
#

Can anyone tell em what's going on here? I've tried everything, I just want these to bake fully without gaps

tardy junco
tardy junco
tardy junco
still minnow
#

yea, ive maxed or reduced that. Done all the obvious stuff

tardy junco
still minnow
#

it's in the screenshot, which is 2, but ive adjusted this and all of the other values to all kinds of ranges

#

this is actually the BEST case scenario in the screenshot

#

I've considered using a collider instead, but I dont want to use colliders across the entire navmesh

tardy junco
#

Hmm

#

Could try making a simplified mesh in blender and build the Navmesh from that.πŸ€”

still minnow
#

like, for the entire map?

tardy junco
#

If that problem is recurring, then yeah.

#

@still minnow actually

still minnow
#

the map is large, with buildings, doors, stairs, floors of those buildings

tardy junco
#

Ah nvm

tardy junco
still minnow
#

yes

#

a few of them

#

i mean, i know i can do workarounds to fix it. Im just trying to keep a decent workflow and understand unitys navmesh

tardy junco
#

Yeah, I donno. Step height should be able to fix that.

still minnow
#

I think its because the render mesh has a curve, that exceeds the max slope of 60

#

and i'd love to script something on a modifier to ignore the max slope or something

#

but i dont see anything about the slope in the code

tardy junco
#

Hmm... From what I understand, step height should have higher priority than slope angle. Otherwise stairs wouldn't have a Navmesh.πŸ€”

still minnow
#

i've put every value into this thing i could thing of lol

tardy junco
#

Yeah, I believe you. Did you try building a regular Navmesh(not a surface)?

still minnow
#

what do you mean?

tardy junco
#

I mean in the navigation tab.

still minnow
#

i did before, but ill try it again

#

what exactly is height mesh?

tardy junco
#

From what I understand it's something to place your character precisely on steps and stuff, but it's something that comes in addition, not to replace the Navmesh itself.