Pagina's

Saturday, 27 April 2019

Objects and children

So, yesterday I added a lot of AI behaviour for the Unfriendly Guy, the guy in the red capsule and it went quite ok. I had some code from my old iteration of the game that had a finite state machine in it and I copied it to the new one, with some additions and changes. When I tested the patrolling behaviour, this happened:


When I could not immediately spot it, I decided to call it a day and have a look later, because it was already quite late and I was tired, but I found it oddly regular what Unfriendly Guy was doing, so no worries. I can fix this easily with a fresh look.

So I turned on my computer this morning and this is what I saw:


Here is the problem. The fact that all was so regular and nice was because the script was working just fine. The NavMeshAgent (the green cylinder) was doing exactly as planned and walking from waypoint to waypoint, avoiding the walls. All I needed to do was make sure the guy was at the same position and rotation. The body was at a different place than it was supposed to be. So I put the Z and Z axis of the body to zero and moved the cylinder to the place where the body was standing, taking the body with me. Now it works.

So, note to self and my first tutorial-a-like thing: when you move objects, make sure you move the right object if they are connected and you want them to be at the same transform.

No comments:

Post a Comment