How do I make npcs run away from me?

Me and a few friends are making a game for the soul purpose of learning the engine.It’s called “Carma” and It’s about this guy who gets dates ruined by diffrent pets.

I have a question about making npc’s run away, The game has 2 modes, A mode where you try to run the cat over with your car. Which would be boring if the cat just stands there or doesnt navigate the neighborhood correctly. And in the campaign you also get to play as the cat and run this poor guys dates, Im going to make invisible target boxes that will make things do stuff like set the house on fire or turn on the fire sprinklers etc. but How do i program the couple to talk and eat and be animated, but then freak out or run away from the cat when it does something? (you can scratch the heck out of people with your claws).

A big thing i want in the game is to use some sort of transform command so that when I hit the cat with my car I would like the cat to turn into a rag doll that hilariously flies around from the impact of the crash and camera to follow the cat instead of the car while it zooms through the air. Hitting the cat Is what completes the level so it would also have to Start the next scene when you hit it.

Another big part of the game is Scenes, The game Is driven by a narraration of the main character from his jail cell, (He finnaly gets a girlfriend at the end but ends up running her over on accident and getting sent to jail for murder where the warden has 14 cats and they all live in his cell with him). I dont know how to make the characters have a pre scripted scene so im going to animate scenes in blender, then make it so that when you complete a level it loads the next video. It would flow well, You hit the cat, watch it sail through the air, Then the game would start the next scene, and when the scene was over you would start the next level.

I would need something similar with The cat levels, When you ruin the date the game plays the next video and continues on to the next car level where you try to run over that cat. And I need a way of doing the same in the cat minigame. Speaking of ending the level, I also plan on adding a car minigame where you can just run over cats, How do I make it so that when all cats are elliminated it ends the level?

Bonus question, How do I make Really intricate animations, I want diffrent choices on how to ruin the dinners, I think it would be funny to have something like you knock over a broom, that falls onto a door, that swings and knocks over something else, that knocks over a candle and sets the table on fire but i wuold have to find a way to animate all that. I understand How to animate your character to have walk animations and such, and i understand how to make the cars work, Level Making is easy for me. But I need an A.I for a free play mode where your a cat and you get adopted by an owner or family and you get to go around and mess with everyone, Id like the family or owners to walk around the house, or start doing dishes, or sit down and watch t.v, etc. and still react to you doing stuff like scratching them and unplugging the t.v and stuff.

Thanks in advanced and im sorry if my question is really vague or not explained well because im very new to this. Especially because I just asked how to make just about everything in the game so if i can get several people to answer small parts then I wont have to waste one persons time. This is my first game on any engine and i just want it to be perfect.

I am with @alucardj - this is too big an issue and it’s not really Unity based. The question is not specific enough and really you should move it to a forum. Even then, it’s still quite woolly.

That said, here are some suggestions surrounding pathing and AI that you would need to understand to progress, as well as a suggestion to do something a lot simpler!

Unity has pathing built in, but it’s pro:

http://docs.unity3d.com/Documentation/Manual/NavmeshandPathfinding.html

Alternatively you could look for some videos or tutorials online or look at the Path library suggested above.

Pathing is quite a big bit of work to bite off - we have a 3D game with a 2D map and very simple compass based movement and it took me several weeks and two attempts to write an A* pathing algorithm.

If you want to try biting it off however, I found this page useful:

http://www.policyalmanac.org/games/aStarTutorial.htm

There are probably alternatives to AngryAnt’s pathing on the Asset Store.

What is your level of programming?

It sounds like you’re a beginner with Unity, so I would suggest you bite off something simple to begin with. Some suggestions are:

  • Two player noughts and crosses (no AI)
  • Space Invaders
  • Break-out
  • Packman clone - has AI and pathing

The point of doing a clone of an existing game type is to make a complete game, understand the components required to make the game and to gain experience in doing it.

As you’re interested in AI, Emil has some great videos on behaviour trees:

http://angryant.com/

Although there is a nuance of his decorator that led me to write my own.

And AiGameDev is the place to go for AI news and articles, but not all of it is free. Behaviour Trees are the way to go IMHO for AI.

http://aigamedev.com/

Reacts BT was being re-developed and should be quite good by now but isn’t free.

You might want to check out Facade, as this is a heavily AI based ‘game’ or social interaction that reminded me of your game idea a little.

http://www.interactivestory.net/

Hope that helps.

First of all let me just say that game sounds hilarious, but some of these things are you are trying to do will require significant amounts of work so be prepared for that if you are serious.

You might want to try using Nav Meshes for your cat to follow. I haven’t even tried them yet and I don’t really know anything about them but I’ve been meaning to watch this tutorial video to check it out for a long time:

I have a tendency to do things the hard way since I want to learn how to program and understand how everything works before trying more advanced features like Nav Mesh.

So if you just want the cat or people to follow certain paths depending on the scene you could try something like what I posted in another thread:

Essentially you would create a series of public transform variables on the cat’s movement script. You would then create empty game objects and place them around the scene at any locations your cat could possibly go. Then you load these empty game objects that you arranged around your scene into your cat script’s public transform variables.

If you name the transform “waypoints” in your scene in a way that you can easily come up with logic for your cat’s movement you can do this kind of thing fairly easy with something like my answer I linked above.

So let’s say you have four public transform variables for your cat:

public transform catWaypoint0; //starting point
public transform catWaypoint1;
public transform catWaypoint2;
public transform catWaypoint3;

You can then use those waypoints to control the cat’s movement based on the distance the cat is from the waypoint.

So let’s say your cat starts at catWaypoint0, and automatically runs towards catWaypoint1. When they reach catWaypoint1 then you could do a random roll for them to turn left or right catWaypoint2 could be left catWaypoint3 could be right.

That’s just a general example of how I might do something like this, it could be that simple or incredibly complicated depending on how realistic you want it to be.

Edit: whoops didn’t realize how old this question was, well hope that helps someone anyways.

the easiest way is to assign a float distance from the npc’s origin. then check if player distance from npc is within the distance, then simple move the npc away from the player by measuring the angle of the player’s vector and the npc’s vector…

it will look very simple because it is - but it’s a start