- Home /
a way to make a simple NPC in 2d unity game
my question is this. how can I make a simple none playing character in unity. I whant it to have a certain area in witch it moves around.
Answer by spinaljack · Apr 15, 2010 at 03:25 PM
Well first you need to make a character model and give it movement scripts that define speed and destination. Have it check each cycle if it's reached the destination and then pick a random destination within a range, something like this:
var dest : Vector3; var speed = 1.0;
function Start(){ //initialise destination updateDest(); }
function Update(){ //check if reached destination then pick a new destination if(transform.position == dest){ updateDest(); } // movement update }
updateDest(){ dest = Vector3(Random.Range(-10, 10), 0, Random.Range(-10, 10)); }
Your answer
Follow this Question
Related Questions
How to move an npc? 1 Answer
Help with chatting to NPC, click F for gui box etc 1 Answer
How to make an model an enemy 1 Answer
Making AI that can navigate through a city? 3 Answers
Prevent bumping of game object into other game object 1 Answer