top of page

Week 4 - Adapting Assets and defining Navmeshes

I imported the created ‘Zebra’ animal asset into the scene. I used this to create a new prefab to which I added a Rigidbody and Box Collider components. I additionally added an animation controller which I used to set a constant running animation to test basic functionality. I created a Zebra behavioural script which I would later use to inherit features from my flocking script.

This was followed by creating a plane with obstacles defined by cubes. I researched the functionality of Unity’s Navmesh and found that it’s efficiency and ability to dynamically update walkable & unwalkable areas would be suitable for my project. I set the plane to walkable as standard and obstacles as unwalkable.

I then replaced the boids with the created animal assets to test functionality. However, boids seemed to move without separation. Instead, they bunched together in a group with no evidence of jostling for positon with the AddForce component. Increasing the force strength worked but this pushed the object too fast and they often became stuck. I realised the problem was that the box colliders were larger than those of the cubes which in turn created undesired effects.

I researched the issue and it became evident that there were different methods of adding force to a boid. ForceMode.Impulse added a quick punch to boids when they came too close. It would usually be used to simulate an explosive shock wave. Separation improved but the movement of boids was slightly too erratic. ForceMode.Acceleration was more suitable as this added a steady force to the boids. But this did not account for object mass which was important when using the same code for animals of various sizes.

ForceMode.Force was the most suitable method of adding force to my objects. It added a smooth force to the boids and behaviour was subject to the objects mass. This gave me a large scope to adapt jostling behaviour for each animal in the game.

Now that the boids moved in a correct manner, I had to adapt movement to work on Unity’s Navmesh. I added a Navmesh agent controller to the animal prefab and used this component to set the destination of boids in my script. I was able to manipulate speed, acceleration, stopping distance and turning radius easily in the agent controller’s scene interface.

Choosing the random destination was a challenge when using Unity’s Navmesh. I created a unit sphere with an origin at zero in the world space. I used the Navmesh.Sampleposition() which chose a random position on a walkable Navmesh area within a specified distance. This worked well but there was an issue whereby a random point was chosen within the parameters of an unwalkable area to which boids could not traverse. I was unable to resolve this issue and will be working to find a solution next week.

I then adapted my boid class to act as a base class to which all animals could reference from. The class was made up of two main functions. One for ‘Start’ which would instantiate all requirements and the other for ‘Update’ where behaviour would update every frame. The ‘Start’ function took in three parameters: Object speed, the players game object and the starting point. The parameters for ‘Update’ were the type of animal prefab which would act as a boid. This allowed me to use this class as a base class which all other animal types could reference from.


Recent Posts
bottom of page