Making NPCs Follow The Player

For various reasons, today I am working on a prototype based on Crowd City instead of my space shooter. As such, I thought I’d write about the NPC movement.

In the NPC script:

  • Two floats to control the distance the NPCs try and stay away from the player.
  • A boolean to indicate if the NPC has been recruited or not.
  • A Transform for the target the NPC will follow.
  • A reference to the Rigidbody component on this NPC.
Variables
In Awake() and Update()
This goes inside the Update’s _followTarget null-check brackets

--

--

Unity game developer / C# Programmer / Gamer. Australian (Tasmanian) indie games developer for 10+ years. Currently looking for games industry employment.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vincent Taylor

Unity game developer / C# Programmer / Gamer. Australian (Tasmanian) indie games developer for 10+ years. Currently looking for games industry employment.