To finish off I've done some work on steering behaviours and generating stories for NPCs in certain circumstances.
For steering behaviours I used the Unity component Nav Mesh Agent, however this didn't allow much variation in the movement for the NPCs. The Nav Mesh Agent was simply too perfect, I wanted to add some variation. Rather than making a steering algorithm from scratch, which would involve implementing a path finding algorithm I continued to use the Nav Mesh Agent, but in a different way. I made the Nav Mesh Agent invisible, with no collisions and wrote a simple steering behaviour to follow that agent.
Unfortunately I left it too late and didn't have enough time to experiment with different variations in steering behaviours.
void Update () {
//Set the speed based on the speed of the Body nav
moveSpeed = nav.speed;
//Set the colour and scale based on the Body
rend.material.color = following.GetComponent<Renderer>().material.color;
transform.localScale = following.transform.localScale;
transform.LookAt(following.transform.position);
float dist = Vector3.Distance(transform.position,following.transform.position);
if (dist > 0.5f){
transform.position += transform.forward * moveSpeed * Time.deltaTime;
}
}
While this code utimately acts in a very similar way to before, it gives me a framework to add that variation which will make the NPCs seem more human.
For generating stories I made a few simple algorithms which searches through all the NPC people looking for specific situations to describe a story. The hardest part was distinguishing between fact and implication. Storing what each NPC might know about every other NPC is a challenge in itself, so I decided not to worry about this too much.
Here is a method for generating suspicions about affairs:
void affairSuspicion(){
PersonStats[] people = GameObject.Find("People").GetComponentsInChildren<PersonStats>();
RelationshipHelper rh = GameObject.Find("Relationships").GetComponent<RelationshipHelper>();
//For every person
foreach(PersonStats ps in people){
//If they are stressed, they have a partner and the strength of that relationship is less than 50
if (ps.stress > 50 && ps.partner != null && rh.getStrengthValue(ps.gameObject, ps.partner) < 50){
//For each of the partners friends
foreach(GameObject go in ps.partner.GetComponent<PersonStats>().contacts){
PersonStats cps = go.GetComponent<PersonStats>();
//If they have a good relationship
if (rh.getStrengthValue(go,cps.gameObject) > 0){
ps.stories.Add("Suspicious that partner is having an affair with " + cps.forename + " " + cps.surname);
Stories.Add(ps.forename + " " + ps.surname + " is suspicious that partner is having an affair with " + cps.forename + " " + cps.surname);
break;
}
}
}
}
}
If someone is stressed and the strength of the relationship with their partner is under 50, they will suspect other people who have a higher relationship strength. The limitation being these suspicions are rather unfounded. There should really be another method for getting more generating suspicions with are definitely correct. This mixture of paranoid stories which are unfounded and real suspicions would add to the variation and complexity of the simulation.
No comments:
Post a Comment