Today I spent a lot of time message around with the more interactive and visual aspects of my game. Namely the player movement and how the people will navigate and steer around the environment. To set this up I decided to use a Nav Mesh Agent. With some help from the official unity documentation and a tutorial on how to make a top down shooter, I implemented a Nav Mesh Agent into my game.
This meant I could focus on starting a finite state machine which will gradually get more and more complex. To test it I wanted each person to move towards their partner if they had one, or move towards there mother. If they didn't have either they would move towards the player.
The final code looked like this:
void Update () {
ps = GetComponentInParent<PersonStats>();
if (!init){
init = true;
if (ps.partner != null){
p = ps.partner.transform.FindChild("Body");
}
else if (ps.mother != null) {
p = ps.mother.transform.FindChild("Body");
}
else {
p = GameObject.FindGameObjectWithTag("Player").transform;
}
}
nav.SetDestination(p.position);
}
I had quite a bit of trouble getting this to work at first. Each person didn't walk to each other, rather they walked to their initial start position. This was because I assigned the variable "p" to parent "Person" GameObject and not the Body which was the part that moved around.
While this system is currently very simple, it should be enough to create some rather complex behavior. Although I am unsure how resource intensive a Nav Mesh Agent is when there are over 100 agents cycling through different states based on different conditions.
Documentation: http://docs.unity3d.com/Manual/class-NavMeshAgent.html
Implementation tutorial: http://unity3d.com/learn/tutorials/projects/survival-shooter-project
Thursday, 29 October 2015
Wednesday, 28 October 2015
Week 6: October 28th 2015
Today I started the bulk of the work involved in porting the Netlogo model to Unity. Organisation was one of the biggest problems with Netlogo, Unity should solve some of those problems. However I am also adapting to a new piece of software so I sure I'll make some questionable organisation decisions along the way.
Firstly I'm grouping all the relevant objects inside parent classes so I can easily loop through every person and occupation. This is equal to the command "ask people" or "ask occupations" in Netlogo. Doing some research this seems the best way to do things, as I can simply get all children from the associated parent class.
Each Person prefab has a PersonStats script which contains all the relevant information for the individual. To represent emotions I chose four variables Stress, Confidence, Happiness and Temper. So far I'm unsure how exactly I'm going to use these. High Stress and Temper levels will result in more extreme activity. Happiness and Confidence will factor into how those Stress and Temper levels go up and down. Finally each person will have a "state" which changes based on those four levels, which influences how they act around other people. This state will act used in a finite state machine.
Firstly I'm grouping all the relevant objects inside parent classes so I can easily loop through every person and occupation. This is equal to the command "ask people" or "ask occupations" in Netlogo. Doing some research this seems the best way to do things, as I can simply get all children from the associated parent class.
Each Person prefab has a PersonStats script which contains all the relevant information for the individual. To represent emotions I chose four variables Stress, Confidence, Happiness and Temper. So far I'm unsure how exactly I'm going to use these. High Stress and Temper levels will result in more extreme activity. Happiness and Confidence will factor into how those Stress and Temper levels go up and down. Finally each person will have a "state" which changes based on those four levels, which influences how they act around other people. This state will act used in a finite state machine.
Tuesday, 27 October 2015
Week 5: October 27th 2015
There will be two distinct simulations in my overall village simulation. One will be a year cycle and another will be a day-to-day cycle. The year cycle will act as setting up the stage, and the day cycle will be the visual continuous game cycle, which will constitute the game. This day cycle will consist of each person going about their daily routine, sleeping, eating and going to work. Each starting couple will get assigned a house, during the year cycle each person above the age of 18 will get the chance to apply for a job.
For each job I have designed a specific routine. Once this is implemented I can focus on changing the individual behaviors of the people to add variation.
Postman - Goes to the post office, goes to each house, goes back to the post office and then goes home.
Office Worker - Goes to the office, goes out for lunch, goes back to the office and then goes home.
Service - Goes to work in the local supermarket and then goes home.
Teacher - Goes to the school and then goes home.
Student - Goes to the school and then goes home.
Nursery Worker - Goes to the nursery and then goes home.
Baby - Gets taken to the nursery by a parent or family member and the gets taken back home.
Mortician - Buries dead bodies.
Unemployed - Stays at home, goes out for food and then goes back home.
The routine for a baby will probably be the hardest to implement, considering it requires an adult to take them to the nursery. It also required adults to adapt their routine based on if they have children or not. I simple hard-coded routine will not be practical in this case. Each person needs a list of prioritized goals they wish to achieve each day, such as "go to work", "pick up baby from nursery" and "buy food". Not only will a system like this add flexibility but it will allow emotions to govern if a task is really worth doing or not.
Saturday, 24 October 2015
Week 4: October 24th 2015
The stories generated through the procedural generation of all these virtual people and there relationships need to be believable, but also interesting and bizarre enough to generate interesting quests for the player to attempt. For this post I am running my simulation a number of times to try and find some implied stories based on individual stats.
Here is the bio for James Stokell:
As you can see he currently only has one half-brother called Ethan Snow and his parents Sophia Snow and Barry Stokell have divorced. He's married to Kaitlyn Stokell with no sons or daughters. His only friend right now is Benjamin Snow despite the fact he's been at his job for 3 years and has an especially bad relationship with Sita Lees.
Next I ran the simulation for 13 more years and had a look see how James was getting on...
James now has a son and two daughters, the son of which he named after his Father Barry Stokell. Unfortunately his marrage with Kaitlyn didn't work out and they got divorced, but he also got a second divorce after getting married to Tara. Now he's "happily" married to Elizabeth. He was made redundant from his job when he was 23 but reapplied and got accepted into the same occupation, perhaps in a different department? This actually happened again when he was 32, seems like his boss keeps on trying to get rid of him, but he keeps managing to figure out a way to get his job back.
Finally I ran the simulation until James died. He lived to the ripe old age of 91. He managed to keep his job at occupation 34 until he was 67 where he was made redundant. However, probably due to his large amount of experience he then became the boss of another company, he retired at 81.
In terms of family he had one more son and two more daughters, however he went through a total of 13 divorces in his entire life.
Looking the life of Jame's you can imply he was probably good at his job, but potentially had some commitment issues with the amount of marriages he went through. Or perhaps he never did any cheating of the sort, but rather he was just really difficult to live with? Or maybe there was a darker reason?
From the point James' point of view he could possibly ask the player to find out if his wife is cheating on him. Based on his previous experience he could be overly paranoid, for good or bad reason. Or since his work is so important to him, when he gets made redundant he could ask the player to "dispatch" a boss of another company so he can take their place.
Looking at the bios of other people in the same simulation, most people have a large amount of divorces in their lifetime. So this is an imbalance in the simulation based on the flat value of the "DIVORCE-CHANCE" global variable. I plan to slowly remove many of the global variables in favour of a system which provides some more individual variance.
Stories involving Sims AI: http://goo.gl/OWtJMm
Friday, 16 October 2015
Week 3: October 16th 2015
This week I focused on implementing friends, enemies and emotions. This would be the final step required before adding events to my simulation, then I can start porting the Netlogo model into Unity and create steering behaviors for each character in the simulated village.
To store every relation a single person has (excluding immediate family) I added a new "contacts" variable. Each contact has a link with the person which owns a "strength" variable indicating how good the relationship is. A positive value represents a friendship and a negative value represents an enemy.
Currently new friends and enemies can only be acquired by a person if they are in the same occupation as them. This will be expanded to friends of friends, and friends of family members in the near future.
I wrote some pseudo code before I coded the procedure in Netlogo:
Each new feature I add to this simulation the more I realise Netlogo isn't suited to this project. With so many links for everyone's contacts, the visual representation becomes useless. You can see all the turtles bunched up around their occupation:
Adding a strength variable to links has resulted in an unexpected side effect. I was only going to use this variable for relationships between people but I could also use to to show how much a single person likes their occupation.
Finally the strength value of the relationship will be used to adjust emotions of people. For instance if someone dies, that strength value will be subtracted from their happiness. Or if someone got fired from their job, that strength value could also be subtracted from their happiness. So if someone hated their job so much it had a negative strength value, it would actually make them happy to lose their job.
To store every relation a single person has (excluding immediate family) I added a new "contacts" variable. Each contact has a link with the person which owns a "strength" variable indicating how good the relationship is. A positive value represents a friendship and a negative value represents an enemy.
Currently new friends and enemies can only be acquired by a person if they are in the same occupation as them. This will be expanded to friends of friends, and friends of family members in the near future.
I wrote some pseudo code before I coded the procedure in Netlogo:
Right now the chance of getting a new friend or enemy is based on the value of the global variable "NEW-CONTACT-CHANCE". It is important I change this in the future to add more "character" to each person. Outgoing people would have a larger chance to make friends, introverts would have less of a chance and especially egotistically people could have a larger chance to make enemies.for each person in simulation {for each employee in occupation {if employee is not already a contact {set rand = random(100)if rand < NEW-CONTACT-CHANCE{set contacts fput employeecreate-link-with employee {set strength random(100) - random(100)}}}}}
Each new feature I add to this simulation the more I realise Netlogo isn't suited to this project. With so many links for everyone's contacts, the visual representation becomes useless. You can see all the turtles bunched up around their occupation:
Adding a strength variable to links has resulted in an unexpected side effect. I was only going to use this variable for relationships between people but I could also use to to show how much a single person likes their occupation.
Finally the strength value of the relationship will be used to adjust emotions of people. For instance if someone dies, that strength value will be subtracted from their happiness. Or if someone got fired from their job, that strength value could also be subtracted from their happiness. So if someone hated their job so much it had a negative strength value, it would actually make them happy to lose their job.
Friday, 9 October 2015
Week 2: October 9th 2015
This week I focused on implementing
death by old age into my community simulation. This is very necessary
to implement future additions to the simulation, such as events and
emotions.
To begin with I looked up some
information on the annual chance of death in the UK. This would give
me a good basis to start with.
Looking at the data I had a few
choices. I could either implement the statistics as a simple lookup
table, or I could use an equation which somewhat matched the relation
of age and death chance. Then I would be able to work out a death
chance using age as the input. The second choice is more desirable,
but I chose the first method because it would be quicker to do and
therefore give me more time to experiment. Later in this project I
will consider using an equation instead, as it would give me more
flexibility in the long run.
Below you can see how I implemented a very simple look-up table in Netlogo for representing the random chance of death. This is limited in a number of ways, and not very flexible, as I mentioned earlier. Using an exponential equation with a number of parameters will certain make it more interesting, but for the time being this will do.
if gender = "m"[if age <= 4[set rand random(4386)]if age > 4 and age <= 14[set rand random(8333)]if age > 14 and age <= 24[set rand random(1908)]if age > 24 and age <= 34[set rand random(1215)]if age > 34 and age <= 44[set rand random(663)]if age > 44 and age <= 54[set rand random(279)]if age > 54 and age <= 64[set rand random(112)]if age > 64 and age <= 74[set rand random(42)]if age > 74 and age <= 84[set rand random(15)]if age >= 85[set rand random(6)]]
For the annual chance of death I used some real-world statistics from the National Statistics series in the UK. Each year a random number is generated for each person, based on their age and gender corresponding to the statistics it it determined if they die of natural circumstances or not. Future additions to the simulation may include diseases, which may also be hereditary. However this could be another simulation entirely, so it isn't very important for the time being.
For death to work as expected, the
simulation is required to perform a “death-clean-up” procedure
whenever a person dies. This forces the person to remove any partners
they were with if they were married, so the other partner can remarry
as a widow or a widower. It also removes them from any occupations if
they are employed, this “death event” is then added to the
person’s job history. As further changes are made to the simulation the "death-clean-up" procedure will be updated to effect the emotions of any people who know or are related to the dead person.
Reference: http://www.medicine.ox.ac.uk/bandolier/booth/Risk/dyingage.html
Subscribe to:
Comments (Atom)



