Multi-Navmesh agent shakes
Asked Answered
L

2

0

Hello guys. I have a problem with multi navmeshes.

It look like this:

So i have a script which Golem follows player when (for example) Vector3.Distance(Golem.position, Player.position) is < 5 and when that Vector3.distance < 2 it stops and rotate to player. You can see that for all the golems player is really close and they want to go to him but they can’t and they’re shakes.

I know that i can create trigger or raycast to detect other golems in front. But 1st i don’t want to use RigidBody and secondly raycast is too expensive for multi nav meshes. They should stop or find another way to player or something. Maybe is any other way to fix that? Without adding trigger or raycasts.

Thank you in advance:)

Lorettalorette answered 26/9, 2023 at 20:8 Comment(1)

I noticed my nav agents started this shaking a few minor versions back of Unity :-/

Shifty
G
0

106245-visual-representation-of-update-metho-200plus.pngHi, I would like to please add a possible solution to this as I have struggled immensely with this.

I hope this can help.

After reading more than a dozen articles I think I figured something out (somewhat to where it looks normal movement of people/nav mesh ai’s etc. etc.).

My solution is not perfect as there is a little bit of “shaky” “pushy” type of movements on the AI side; however, it is far less and more realistic movement than its current way of doing things.

I had a problem with 200+ AI Nav Mesh Agents do the “Jiggling”/ “Shaking” effects when they would all target one object. (in my test experiment scene). As they were all trying to force there way to that target.

Things I tried

Setting Avoidance Priority; however, I soon found out that the priority level only goes to 99. so having double the AI, that couldn’t help.

I Tried setting the Nav Mesh Obstacle, and that made the shaking/jiggling/pushing of AI even worse.

What I found that is working for me as a work around using C#

I made sure rigidbodies was on all my AI characters. (In my test I set continuous dynamic for collider detection)

I made sure Sphere Colliders was on all my AI characters, and set trigger on.

In my script I simply did this method (I apologize for my wording, and comments)

// detect other gameObject tags that are not player, stop pushing other AI's away
void OnTriggerEnter(Collider other)
{
    if (other.tag != "Player") //tag not like player 
    {
        this.GetComponent().isStopped = true; //since tag is not player stop this AI movement
    }
}
// opposite from enter detection, make AI move on path again
void OnTriggerExit(Collider other)
{
    if (other.tag != "Player") //the tag is not like player has left my trigger collider
    {
        this.GetComponent().isStopped = false; //make AI move again after trigger is over
    }
}
Gavriella answered 26/9, 2023 at 20:4 Comment(3)

Wow! Thank you so much, sentar! It will be quite useful!!:)

Lorettalorette

Hi Mauhan, I'm glad to be able to help. I know this isn't exactly what you are looking for; however, I hope this can get you on the right track! :) Sincerely, Sentar.

Gavriella

No, you clamp it from 0-360 and if rotation tries to go below 0 you set it to 360 and if the rotation goes above 360 you set it to 0. It does work as I have got it working well in my game.

Fingering
S
0

Hi, i know this post its kinda old, but

In case anyone in the future looks at this post, i think its worth mentioning that setting NavMeshAgent.destination to transform.position can also cause the agent to shake. Especially on android builds (even if it doesn’t happen in editor).

If you want to cancel the NavMeshAgent.destination you should use NavMeshAgent.ResetPath() instead.

Sidewinder answered 26/9, 2023 at 20:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.