Companion AI

Inspiration and goal

After playing Bioshock Infinite and loving the way that Elizabeth moves and guides you without being in the way, I decided to try and make a version myself. 

My goal was to make a companion that would help you get to a goal by guiding the player.

This project was for 5 weeks at 50% workload. 

What is the end product? 

I want the companion to walk with the player, in front of them, as a guide would. The companion should not walk too close to the player and cant be too far away so you lose track of where it is. 

The companion should be looking at the player if the player stands still for to long.

The companion should find a new path if a shorter one appears.

So to achieve this end goal i made smaller goals. 

First goal was to have a NPC just follow the player around in a sceen in Unity. This was the goal for the first 7 days. I had not used Unity in more than a year and knew it was going to take a little while to get into it again. 

How I made the first goal: 

I started with just making a Unity scene, and making a PlayerScript, ThirdPersonCamera and a CompanionScript. The Companion uses NavMeshAgent to find a path, but the Player does not. 

My second goal was to make sure that the player has an end-goal that the NPC should guide them to. I also want the NPC to not be in the way for the player, so to stand a bit infront of the player and within a radius. 

How I made the second goal happen: 

The Companion calculates a path from the players position to a cube I put in the scene. It uses the cube as the goalposition, uses pathfinding and tries to go too the closest corner. But it uses a radius from the player, so the companion wont be to far away. So it finds a point on the path to the closest corner within the radius of the player. 

The third goal was to have the NPC find new paths if a shorter one is found. I also want the NPC to look at the player if the player is not moving for a while

If I had more time

If i had more time I would have liked to make the NPC find points close to the player, one to the right and one to the left, so if the player turns it looks more organic for the NPC to move to one of those ponts.