I'm having some interesting behaviour with NavMeshAgents. So I've been working on a project for the past few months which is revolving around creating believable enemy AI systems for stealth games. When the player kills an enemy they can pickup the body and put it into a body bag, this all worked well and fine for a while but now once the player has picked up two corpses all Nav Agents do this.
They are still in their patrol state (using a behaviour tree) and all of the AI have a destination set which can be seen on the debug tools for the Agent. However if I try to move the AI whether that being dragging them around or setting a position through the inspector they will snap back to a corner of the NavMeshSurface.
Using Unity 2021.1.17f1 and using the latest compatible version of the NavMeshComponents package provided by Unity.
Things I've tried:
Changing Radius and Height of agents
Setting the floor and such as navigation static objects
Removing the NavMeshComponents package scripts and replacing them with the original NavMesh system. Didn't work and took a lot longer to build the NavMesh
Interesting behaviour:
The amount of body bags the player has to pick up seems to be related to how many AI are in the scene. For example currently there are 23 AI and it takes two body bags for this glitch to happen, but if there are 24 to 31 AI in the scene then it requires three body bags to be picked up for it to happen.
All calls to the NavMeshAgent are done through a AILocomotion script which handles enabling and disabling rotation, movement and updating the animation. Movement is only disabled upon death or when the AI is in the wait state, other than that every Move based state re-eneables movement.
Update: Found the solution
It turns out Unity does not like it when you destroy a NavMeshAgent component during runtime. Now when the player picks up a corpse it leaves the NavAgent behind but destroys the mesh and colliders etc.
Related
I have multiple GameObjects in my Scene.
There is some Package, player need to collect this. BoxCollider2D is attached to them. Here is the configuration :
Here is the player's configuration:
Another configuration of player:
Intentionally placed to Collider, so one can detect body touch and another fall over head of package.
And there is also a walkway. Here is the configuration :
Every RigidBody2D has Continues collision detection.
Still it creates problem, first everything is cool as it should be. Later Player stops colliding but collides sometimes. Why is that ?
What can be the probable cause?
Here is scene-view :
Here is some shots :
https://drive.google.com/file/d/1DoWSG0hlZZb0KIX-oUWI8FPXK5HepppY/view?usp=sharing
Big File for Stack Overflow - 35MB
Here is the project : https://github.com/maifeeulasad/Slicer2D-Unity
When using the unity editor all animations tied to the camera work, but when build and deployed onto the hololens the animation wont process(being overridden by real life coordinates), the way to get around this is by attaching it to a random gameObject. My issue is giving the user the ability to roam around space whilst tying animations and force movements to the cameras parent(empty gameObject).
I have tried making the gameobject stay where the camera is but obviously this just makes for constant motion.
Is there any way to keep the cameras parent exactly where the camera is in order to stop the animations going glitchy?
So initially I had trouble with my character's left arm and gun clipping through objects(not entirely though) and I followed the instructions in this unity3D post to fix this issue(Read through the top answer so you know what I did).
Solution for FPS gun clipping through walls
Now I'm having trouble figuring out how to stop my player left arm and gun from rendering twice when he starts running fast(Doesn't occur when I'm just walking or slightly running). I know it has something to do with there being two cameras but I need an additional camera to stop the gun and the player's arm from clipping through objects.
Here is a picture that shows what I mean.
IF you look closely, you can see that the AK-47's magazine is being rendered twice(there is very small gap there) as well as the left arm. I've fiddled with both camera settings and could not figure out a way to stop this from happening. How do I go about fixing this issue?
You need to disable the gun layer from rendering with the first camera. The gun layer should only render on the second camera.
I am currently working in a Unity 3D project (in version 5.0.1 to be precise) in which the character can walk in different-shaped planets without falling. So it is always attracted by the planets gravity (similar mechanic to the Super Mario Galaxy games).
Now, the problem is when I try to code the AI for the enemies. This AI should be pretty much simple, but because of this thing that I have with the planets shapes, I haven't been able to come up with a solution. The enemy should check where the player is and move ahead to its position. It's a really dumb enemy. But the thing is, that the enemy must be able to track the player and get to its position no matter what planet he is in. So, if the planet is circular, I cannot make the enemy look at the player and then move forward, as I would do in a plane planet.
I have already tried using a NavMesh, but Unity doesn't want to collaborate and ends up making a NavMesh of 1/3 of the planet. I don't understand why. I have tried changing every single parameter of the NavMesh baking but I haven't succeeded.
Another problem that I would like to do is: ¿How would you make a player be able to walk on the surface of any planet, no matter what its shape, in a smooth way while using a Mesh Collider? I am currently achieving this by getting the planet's normal with a raycast, rotating the player so that the Y axis is perpendicular to the normal and applying a force in -Y to simulate gravity. But this brings lots of problems when I implement the Mesh Collider. It results in a jittery effect. But, when I use a primitive collider from Unity, it works fine...
Anyway. What I need the most now is the answer to the AI question. The other one is kinda like a plus.
P.S: It doesn't matter if the solution is in Javascript. I can then translate it to C# :)
At the moment I've set up a dual camera scene in Unity. I've created an empty game object for my camera's to inherit from and attached some of the first person controller scripts to this empty game object.
When I run the program in the editor, it runs fine. When I build the project, the game crashes and my camera objects fall through the ground. I've never experienced something like this before in Unity. Attached is a copy of my my current fps set up values.
In the picture, you will see that I have turned gravity off (set it to 0), yet it still falls down when I run the built program.
Has anyone ever come across something like this before? I've spent all day trying to fix this, but I'm getting no where.
I experienced such an issue when my parent object (I usually use capsules to "carry" the camera as the players head like 1.70m above the ground) is set to low ... what happens if you move your camera-guy together with the game object one meter upwards? (so that he falls down a bit against the surface when you start).
Maybe there is a difference in some relations between editor-build and release-build.
Or, in case this isn't the solution, check the spatial positions of your involved objects again. Falling through a terrain is often produced by misplaced reference objects. (I sometimes hung a carrier object under a camera instead of hanging the camera under a carrier object.)
As you say that it works in the editor-build i assume that you have activated collision for the relevant objects.