Thursday, October 20, 2016

Wednesday update #6 late - Hump Week


It's been a tough week, hard to get into it this week for various reasons.  I finally got the momentum going again last night, but technically that was Thursday, so really a very poor return this week:

  • Got a training area.  I plan to make the AI work itself out here.  So rather than mess with the main scene I created a trainign scene, and plan to build a whole lot of scenarios into this scene.  It will be sort of like an AI unit test, although I'll have to visualise the results, but it's just too difficult to do other ways.  The plan is to make changes to AI, then run this in as many scenarios as I can, and watch the AI do it's thing.
  • Cleaned up some code.  Creating a new scene showed me there too many weird dependencies in my classes.  I couldn't add AI to a player, without having to add this to the scene, with then needed the manager, etc, etc.  I have cleaned it up a little, though for the most part I just added the components, I need to move on.  Also, as I work more in the AI classes, I plan to clean up the code somewhat.  The structure isn't too bad yet, but evertime I come to an AI class I haven't seen for 10+ days, it takes me 10 minutes to work through the decisions.  I think In future projects, I may end up adding a tonne more AI classes, specific to different ideas, with descriptive class names.


But to be honest, I didn't get any real traction on any real work.  I'm hitting a bit of a wall when it comes to drive on this project.  I guess I came in thinking, that if someone who likes Aussie Rules games hears about this, I will get a lot of support, that might grow and grow by launch.  But there are many factors playing against me.  Firstly, I have never actually written a game.  Love sports games and complain about them as I do, this doesn't make me any more of an expert then 50m other sports gamers.  This really reduces peoples care factor about what I'm doing, because they (maybe rightfully) don't think I can do anything good at this stage.  I think another factor is the limited scope I'm aiming at.  It's a catch 22, because I don't think I could have finished a project if I was aiming at a fully blown console version.  But then nobody really wants a cut down version.  Then I guess it's just a bit disallusioning looking more into the future of what is indie dev for me.  If I can't even gather any interest in a specific sport with a huge lack of games in that area, then what chance do I have competing in bigger markets as a sole developer?

Well, last night I got some decent stuff going, so I'm back on focus again now.  I figure I'll do this until end of November, try to deploy as a beta to android, perhaps even IOS, and re-assess.  But there is no point putting in a half assed final 6 weeks, and looking back and saying I couldn't get any support.  At this stage my final hope for getting some support is to really work hard at making a decent fun game, and hope those that do step up to have a go like it and spread the word.  So this week I should be:

  • Working on unit testing.  That is boring code talk, but it essentially means my AI will have a set of conditions it needs to pass.  I did half of this Thursday, when I set out the conditions for when and how a player should get to a contest, but technically that's next week.
  • Work on getting to a contest AI.  There is a lot of AI to think about still, my first target is to get players to intuitively get to a contest, thinking about other players, the ball etc.
  • If I still have time, it's then collisions.  The biggest difficulty is going to be making a non-repetetive way for players to collide, be it the bump before the contest, a player flying in from the side, 3-4 players all going for the jump at once.  I have some ideas, though the code for this one will be interesting to say the least.  My ideal is that my unit test scenarios will produce not only somewhat realistic contests, but also not the exact same contest each time.  Like occasionally one of the 4 players should jump too early, because they are nervous about the upcoming contact from up to 3 players.  Yet other times they should nail the jump, and perhaps even take the mark.  But it is important to keep it simple first, so something there will likely give.

Wednesday, October 12, 2016

Wednesday update - half way point and screenshots

I have achieved what I set out to this week in terms of rounding off some of the gameplay options:

  • Scoreboard - this is now showing the score as well as menu options.  I also added a similar styled scoreboard in the game itself while playing.  I would have just gone a TV styled score tracker, but again through the grass roots idea would benefit from an old fashioned look to the in game score, I think it looks good.
  • Timer - again my default thought was a timer shown in a computer font, but again the old grass roots timer came to mind.  It's something any WAFL/VFL fan would instantly recognise, so it is now a must for my game.  Getting the hand to cooperate took more time than I'd hoped, and in fact the main one is still not working 100%, but it's mainly useful for in play, so you can now get a feel for roughly how many shots you might have left.  This will not only leave a little nice feeling see that style of clock, but also hopefully give a feeling of nerves.  Those clocks don't tell you exactly how long the game has left, so it's a bit of guesswork needed, good for nerves if it's a close game.
  • Gameplay options - I was a little worried about this, but it came together nicely.  I didn't want to complicate things too much, so kept to some pretty simple rules.  Firstly, the clock ticks a minute (of actual play time) and randomises whether opponent or you can get a play in.  For opponent right now, you pretty much just see the result (may choose to allow a defense against CPU later), for out turn, we get to play.  When we play, you'll notice in the top, the clock has moved on, and the score may or may not be different if opponent has scored.  The only smarts I'm building into the strategy, is if you get 2 goals in a row, the other team drops a player in defense.  This makes it a little easier to get it into your forward line, but the extra defender makes it harder to actually score.  Apart from tweaking the randomness a little, this is now pretty much complete.
  • Graphics - had a little less energy last night, so I just played around with a few graphics things.  I added a hot dog stand, and right where it used to be at Lathlain Park.  I added the 2nd stand.  I found a park bench that I will use a lot of, but putting it in the stand (as it is in real) doesn't look right yet.  Plus it adds 100+ detailed 3D objects to the scene, so not sure this will stay.  I might create my own very low poly bench for stands, and just never do real close ups.


As for general thoughts, it's been a yo-yo week.  A little on a high thinking that I'm half way done now, and I have a decent amount of game already behind me.  But I have a nagging problem I can't shake off.  If I release it as planned, it may well be fun to play, but for the random player, just playing any sports game without a league or something for it to mean something, will leave it too light.  If I saw such a game without knowing any background, even if I loved the gameplay, couldn't leave it a 5 star review, as it would feel incomplete to me.  Then if anybody doesn't like the gameplay, or finds a few bugs, might reduce it more, maybe even 1 stars.  If you don't get any 5 stars, but you do get some 1 stars...  it won't end up a good rating.  It doesn't mean that much in reality, as I know why it's not great rating, but it's still a public showing of my skills, and 2.4/5 isn't something to brag about.  Essentially, while the 12 week project is a great idea to get something up and running, and get something done, it's a little weak when it comes to app store releases, especially something like this, where not having a league option is an obvious hole.  I now figure I might get away with a public beta.  In this way, I can still release it in 12 weeks, but nobody will assume it's a fully finished product, and will hopefully mark accordingly.  I will still aim to do this on android (have checked google play, it's possible), and hope to be getting a Mac very soon, so then will start looking how to do this on ios too.

Next week it's back to player AI again.  I'm going to start with 1 on 1, but with the idea that it could be 2 on 2, 3 on 3, and any of those plus a floating defender.  But I imagine I'll be working on the 1 on 1's for some time still, as it's easier to identify and fix bugs.  If I get a bit of lighter time, I still have a lot of the ground features that need to be finished.

Screenshots:

Main menu.  Was a 2nd option, but it's not planned now, so just removed it.  Side white bar is an ad bar:

Start of game.  Our guy has the ball up the ground, you drag the full forward to give him a path

After taking the mark, camera drops back behind player to take a shot:

 1/4 time, and we go back to the scoreboard:

Wednesday, October 5, 2016

Wednesday Update #4

Very little real time since the last late update, but some progress has been made still.  To be honest, I've been fluffing around the big issues of AI and collision, but I feel on any day I can be in a position where I want to demo my game on my phone (happened quite a lot on holidays), and while I was proud with what I had to show, a few days work to fluff up the graphical side of things would have made it far more impressive.

Work done in the last couple of days:

  • I have a logo.  I created a facebook page now, and it asked for a logo, so I created one.  It's not too bad, and I've already put it on top of my scoreboard, which I think looks nice
  • I had a side thought about how to manage instructions in this game, and came up with a coaches whiteboard, so whipped one up.  I found a handwriting font, so it looks a little more like the coach is writing on a whiteboard.  It doesn't look spectacular, but is nice, and lerps in and out from the side.  I aim to use this for "commentary", which will effectively be coaches tips at 1/4, 1/2 and 3/4 time... assuming I have time to do this.  At very least I may have an array of encouraging comments for these breaks.  There is then a "got it" magnetic sticker that the user can press so they don't need that instruction any more.  The whole thing works quite well I thought.
  • I had various thoughts about this game being too easy, which essentially it would be in real life with just a 1v1.  The forward can lead anywhere they like, and without AI cheating, it would be very difficult to stop them getting a mark.  But if I allow more than one player to control my discs, which I didn't love anyway, won't work.  I also had a very simple approach to a moving version of this game, for mobile.  Drag a player to move them, tap to pass.  This works actually somewhat better than console sometimes, because I can instruct 3 players to move in directions, then tap to pass it to the one that works best, this would be difficult to master with xbox.  Well, I got it working.  Now, when you drag your finger from a player, it plots out points every 4m or so (felt about right) and shows it while you are still planning.  Then you press play, the path disappears, but is remembered by the player and they execute.  Once they get to the last point, the AI kicks in again, and if you don't want that you should be able to drag them again, though it doesn't currently allow this, and I may leave it out of V1 for simplicity reasons.  The way it works is it starts a tracking if MouseDown (also finger down) hits a player or their disc, and then tracks until mouse up.  It only stores points if they are 4m away from the last point, which works well, even if they completely change direction.  It stores those in a List of points for the player, then the various AI elements check to see whether that List is empty.  If it's not, the AI follows point to point, deleting points when they get close enough.  When all points are gone, other AI elements will again wake up and decide where to run to next if needed.  If the ball is kicked, the path is also destroyed, and they will either go for the contest, or not depending on where they are, who they are.  This works really well so far, and the player changes direction in quite a realistic way when following crazy paths, as I made them slow down more the larger the change of direction is.


That is all so far, and the list of changes needed don't seem to get any smaller.  Here is a somewhat brief overview:

  • Game management.  Have a main menu, can reset play, it tracks scoring.  But, it doesn't show the score.  I have a scoreboard, but am not thrilled about panning in and out all the time to show this, so would like an on screen score.  This could get tricky, as I've noticed I can't assign free text to the instructions board, and completely different free text to another element.  I'm cheating around this by making images of common wordings (like "got it", "Play", "Start new game"), which I may just continue to do, or find a better way to do text.  Other management issues not yet tackled include 1/4, 1/2, 3/4 time breaks, AI for opposition scoring, storing any setting change, previous scores.  There are stacks of bigger things, but that will be V2 if ever.
  • AI.  It's off to a nice start, there are plenty of minor bugs still.  I need to also think about when not to run full speed to places, such as getting to a contest still jogging, not sprinting to a stop and then jumping at contest.  When to run backwards, when to brace for a collision, when to lead or hang back.
  • Contest.  Similar to above, but worthy of it's own section, this is nearly non-existant so far.  So I need to build good physics around bumping into players, wrestling, diving for a ball, change of direction.  Not really AI, but more physics around how things will work.  This is vital, if I get this right, the game will feel right, and if feels right, it will be a good game, pretty much that simple
  • Graphics.  This area improved a lot, and I need to focus just on what I can easily achieve I think.  I need to paint the bipeds with football clothes, which I started and wasn't all that problematic.  I need to check through the animations and get those looking OK, especially around contests, though animations are going to be a weakpoints, and there is no easy answer there.  I need to work more on the home ground, though it looks OK for now, so this might be a lower priority.  Scoreboard still needs completing for when showing scores, not the menu.  Grass textures, ads on signs/field, crowd, umpires, animations for celebrations, coaches, kick to kick, these are all on the way too low priority right now, AI/Contest are far more important.
  • Sound.  There is none right now, and perhaps by V1 release too, again due to not being as urgent.  What I do have planned is crowd noise, football impact, collision noise, players calling.  I'd like noises for pressing options, music in the background.  Options to turn sounds off too.
  • Sound.  There is none.  However unfortunate, it may stay that way too


Looking at that list, I could spend a bit more time getting the ability to play a game with scoreboard going, which I'm only a few steps away from, so perhaps that is my main focus by next week, and then AI/contest has to become most of the focus:

  • Fix any bugs around end of play, should be able to also go to next contest without fuss
  • Show scores after each play, and the score during play.  I'm thinking of using a scoreboard like material and images to place on top rather than free text, somewhere central and big for current goal/behind/miss, and in the top right corner for current score, to give it a more authentic feel, will see how that looks
  • Have a 1/4, 1/2, 3/4 times and game finished.  Show the full scoreboard with proper scoreboard look at these breaks too.


Sunday, October 2, 2016

Wednesday Update #3 (Sundayish)

This will still be basically Wednesday, as I flew to Melbourne Thursday morning for a few nights away, and have done nothing since.  In fact, I was away from Friday before that with family and did nothing then either, so very little has happened.

I did get a few little pieces in:

  • Discs under players.  I will get some player looks done sometime soon, however I still don't know that will quite be enough.  I also like the discs under players in AFL TV shows, and realise it's pretty easy, so did that.  I put a 2 colour material on it, so we now havve noticable teams, blue and yellow, and red and black.  If the player has the ball, the disc spins too, so it's obvious when someone has the ball.
  • I also added a trail to the ball, to make it more noticable where the ball is and the angle it's going.  It's as simple as a Trail Renderer in Unity, and took only a few minutes to tweak into something quite impressive.  I might have to stop it when a player does grab the ball however, as it's more for when it's being passed.
  • I also took a couple of looks at the AI, mainly stopping the crazy running in circles, as it's driving me mad.  I tried to slow down when trying to turn more than a few degrees, and also to be more liberal in knowing when they are almost at a target.  Still not there, needs more time.


Most of all, I've changed the scope down to a total of 12 weeks work, from when it started.  It comes back to an idea from the Unity forums, which is to get something released.  The theory is if you set your ideas too big, the end line can shift, things can get a bit too hard, other projects come up, etc, etc.  It's essentially easy to not finish something, and always have that idea that never really led anywhere.  So the 12 week idea is to get something released in 12 weeks, just get something done.  Beyond that, is yet to be seen, there are so many variables.  In my honest opinion, it may need some support to go too much further.  I'm not necessarily talking financial, more just community support, which I'm hoping to get from a football forum, and perhaps even just from downloads/ratings on the app stores once live.

The 12 weeks will be essentially end of November, and I've really warmed to this idea, as it gives me a harder deadline, but that allows the scope to stay small, and perhaps just to grow as needed from there.  Also, in reality December is a difficult month, so having something out there is probably better than to be expecting to work on it hard.  Perhaps it's a good time to work on some post release work that is needed, if nothing else clean up some release bugs that come up.

So not much to report, but hopefully it's back on track this week.

Wednesday, September 21, 2016

Wednesday Update #2

A lot of good things have happened this week. I'm still quite shocked at how easily things have seem to come in the first few weeks of using Unity.  I'm not saying there aren't concepts that are well beyond my current skill level, but when I do think of doing something, it tends to be something Unity has accounted for more often than not.  You know, it's kind of the opposite to a lot of things, eg. Netflix (OK, Netflix AU especially).  When you browse Netflix, it seems wonderful and grand.  Like a framework that demos all it's strong points in an instructional.  But if you search for a specific film on Netflix, it's massively dissapointing, quite like having an idea, and seeing your code framework won't support it.

It's difficult to know just where to start for this update, I think I'll just do a walk through of how the game currently plays, and how much I've done in each area.

Firstly, a little theme overview.  Having no licensing for a sports game poses problems.  No matter how you put it, people love characters and teams, sometimes more than the sport itself.  So while the obvious route would be to make a fake league that mimics the big time, I'm going a very different way.  I'm looking at creating a grass roots game, with the look and feel of the smaller leagues, with it's small but passionate crowds, interaction, kids mucking around on the oval, ice cream truck on the hill, mates with eskies, old fashioned stands and scoreboards.  It might seem an odd choice, but it really fits with me.  I go to big games sometimes, just last week went to a game with 60K crowd, last year 100K grand final.  But I honestly enjoyed if more in a 6K crowd a few years ago when my team travelled way out of the city to play the newcombers.  Best of both worlds for me, good football, good atmosphere and feel.  I really don't gel with the sardine like stadium seating, long queues and massive prices for anything, an hour to get out of the carpark.  I figure I have to be true to myself first, and in doing so can hopefully catch a few other hearts out there too.

So, in saying that, here is the run through:
* Start.  Last Wednesday I had a functioning start menu, with one working option, Start New Single Player.  It was a 3D floating canvas, and looked fine, but I had concerns over how to get that to the next level of look and feel, not my strong point.  Even the crud AFL games have some slick menu systems.  It came to me Saturday.  If I'm going grass roots, what better way than to display the menu on a grass roots scoreboard.  I already had the scoreboard, so quickly added a couple of cubes, put an image of a nice old scoreboard font (similar at least) saying Start New Single Player/Multi/Settings.  It stuck my eye that the scorebaord was black, just just windows paint black.  I looked around for how to make it look more realistic, and settled on a hybrid image, which blends between black and grey in a random sort of way, and now it looks a little tired and worn, excellent, a real scoreboard.
* After you click Start, you go straight into the game, and have to choose what your full forward should do, lead forward, drop back, or move slowly to the middle and wing it.  Not much has changed here, there are 3 discs that appear, click one of them, choice is made they slowly disappear.  After choosing, the AI defender chooses what defense they will attempt, and a 3, 2, 1 countdown begins.  I loved the discs at first, but am less fond of them today, they may go, I might get the user to drag the player to where they want them to lead to instead.  The countdown may go too.  It's mainly there to allow for networking problems in multiplayer, so attacker and defender can make a choice, it's an indication both of you have chosen, but come to think of it, I'll probably just have a sign showing that other player hasn't chosen just yet, no need to slow people down with a 3/2/1.  Although it's still nice to know how to do it.
* Once the countdown finishes the player starts doing what you told him, and the defender does the defender AI choice.  There is also a player further up with the ball already, and another defender on them, and they are just staying there as if in a marking situation.  There is a tonne to do here still.  I have lost some AI code here, I want the AI to allow player or defender to be able to choose a 2nd strategy if their choice is clearly not working, but that shouldn't be too difficult to add in soon.  I will also look at adding more forward/defenders, as 1v1 seems a little easy.  I might even make this fairly random, so sometimes you do get the 1v1, other times it's a crowded forward half.  Perhaps it's not even that random.  After you kick 3 goals straight, AI decides it needs another defender, so suddenly there is a spare defender too. Less random = better in my opinion.
* You then tap somewhere on the field to pass it there from the half forward.  To be honest, this part still feels fine.  One part I love is that a player can make the decision to pass it anywhere quickly, because there is usually a big disconnect here between player and what button to press.  Eg, in a Madden situation, I have to learn who is XYAB, and while the play is on I'm trying to remember which button is B, woops got it wrong.  In real life, the difficulty is knowing how far in front to pass it, not looking down to see if it's button B.
* So the ball is kicked, and the full forward and full back forget their leads now, and try to get to the ball target.  If they get there early, they stop.  This is technically not wrong, but it looks silly, they should slow down to a jog if they are getting there too quickly, or perhaps wrestle/bump first if they aren't open.   But it's fine for now.  They at least aim to meet the ball before it lands at good jumping heaight, and jump at it.
* Next up the contest.  Forward and back both jump at the contest if they are close enough, with forward trying to mark always, back happy enough to spoil unless clear.  This is one of the biggest areas that needs improving.  It works OK, but the contest is one of the most important parts of the AI/animation if I want to get a realistic game.  We should have things like bumps, players jumping over others, etc, etc.  But for now, it's simply if I'm more open I'll mark, otherwise it will be spoiled, which is OK for now.
* If the forward takes a mark, they line up for goal, and the defender stays on the mark.  This is all new, and I love it with minimal efforts made so far.  Something to mention here is the camera.  I had a 45 degree, behind the goal view for the game, but when I changed the menu to the scoreboard on the hill, I added a pan back to the game view position and rotation, it works so nicely.  So I did the same here, and for the first time, you are down with the player, staring at the goals.  At this stage it's a simple task, just tap somewhere on the hill behind the goals, and it sails through, but I will add some difficulty to this later.  A box collider registers it as a goal/point/out of bounds, and the player is shown this result on the screen.  It's a 3D text at the moment, but will probably be soemthing fancier, and likely even have the goal umpire running round doing their thing later.  I also want the player to celebrate/get upset depending on result, talk about this later on.
* The result stays on screen for 3 seconds, then the camera whips back to the top down view, and you start again.  Scores are kept, but nothing gets displayed at the moment.  There is also no exit/skip function, and it's possible to get stuck if a mark isn't taken.  In this case the players keep playing, and you can even still score a goal/point, but if you don't there is no way to stop the game.

Overall, the AI is still very weak.  As has been shown above, I've played with quite a few areas this week, and while some new AI has been added, I still haven't replaced everything I lost a couple of weeks ago.  But there is random strangeness creeping in in most areas.  For example, if I mark, the defender correctly goes to the mark, because they are closest.  But then the other defender comes down, and also tries to stand the mark, while his opponent drifts into goal for an easy mark and goal.  Also, I had no animations until a day or so ago, but added idle and run recently, then jump and kick(s) last night.  It works fine, but I had to stop just moving players around like chess peices, and instead get them to rotate to where they are running.  Before, if there was an overshoot to the right, they'd whip back to the left, and so on, left/right/left/right.  Now that they turn and run, when they overshoot, they start running circles around their target.  It's easy enough to fix, but I need a more realistic solution, which will include a lot more animations (eg. stop running hard, turn back to the left) and physics (don't run in a big circle to turn around, slow down, change direction then start running again).  If I kick at goal the raycast hits an invisible collider, so players start running towards the hit point, which is 5m in the air, so they float up while running.  Very funny, but very not life like, and any one of these things will immediately take you out of the game feel, so I need to get on top of these things.

I'll call it quits on the Wednesday update, but have a bigger scope sort of email coming up too later.

Wednesday, September 14, 2016

Wednesday Update - 14/09/16

A lot of stuff can happen in a week, and I really want a track record of where things are going, and where they've been, so this will be a weekly post.  As my skills grow, I may even set weekly goals, but as this is a hobby project, and my skills are low, I'm just happy to progress much week to week.  Suffice to say I am working off a goal list, but timelines are not a problem for me yet.

First, I'm trying to work out the start point of this project.  I came off the rush of programming an olympic schedule, and spent the first week of the olympics updating that app, and Web Api with schedule updates and medal tallys.  But as the 2nd week came along, most things were automated, and the app was good enough to leave alone, so I stopped there.  For about another week, I started a 2nd Android app, which I still intend to finish, although I'm waiting on a Mac, as I'll probably start my 2nd app as an IOS app first just because, well... because.  Then I got hooked on the idea of writing this game.  I first started looking at the OpenGL libraries, using the OpenGL ES from Android Studio.  I managed to get a 2D version of my sprite player charging at the sprite ball.  About half way through that process, my work colleagues told me Unity instead, which I ignored at first, because who wants a factory to build a tanker when I'm trying to build a tin boat.  But I read up on it anyway, and eventually decided to give it a go, and I was instantly hooked.  Sprite moving from A to B came a lot easier, so much more fun to do, so much more power, C# code, I think I'll be here a while.  But then the more research I did, the more I kept hearing Unity is kind of 2D retrofitted, and you should just start practicing in 3D at least, so I did.  Once again, hooked!  I'll put a start date of my Unity 3D game to somewhere around August 20, which sounds insane as that's only 3-4 weeks ago.  Seems like a year ago, but the dates don't lie.

So much has happened in those weeks then, that it's going to be really hard to sum it up, which is why I probably need a weekly update to all this.  First of all, wow, it's mind blowing how much thought I've put into this so far.  It's an idea that's been a long time coming, but the details are flowing through in a huge hurry now, partially with the game, partially with Unity and game programming in general.  I'm pleased to be putting a lot of effort into it, but am still hamstrung by time, with a day job, family, etc.  Programming has a very slim amount of time to allocate, but I'm getting decent chore time to listen to youtube tutorials, or just think out some concepts.  It also hasn't hurt that weather has been pretty average, so I've been on the train a lot more recently (as opposed to bike commute), more time for youtube/planning.

Learning 

Which gets me to my first update, learning.  I've been doing a tonne of this.  My usual podcast routine has been rudely interchanged with Youtube Red videos.  I probably do 10+ hours a week of mindless chores and used to listen to podcasts/music, but now it's Unity videos.  Some of it escapes me as I focus on what I'm doing, but I hear a lot of the same concepts, so they are starting to seem familiar.  I'm mainly focusing on beginner stuff, because I don't want to spend 3 days doing something basic that I could have got from one of the many basic tutorials.  New to Youtube (aside from music, and the kids watching Dan TDM drone on), I'm finding the big challenge is a big clear voice to listen to, especially as I'm rarely sitting in front of a TV/computer when watching.  Speak up people!  My memory does me no justice at all here, as I'm sure I've seen a lot of good videos I can't remember now, but the highlights have been quill18 and Holistic 3D so far.  Very different approaches, but easy to follow, loud, and interesting content that seems to flow nicely.  I haven't found a good book yet, though reading is not my strong point anyway.  I feel like while I've seen videos touch on almost every part of Unity that I'm interested in, I am still (obviously) getting by on very little real knowledge in Unity.  That said, a lot can be done on very little knowledge, which is what I'm really enjoying about it.

AI
  
Since it's one of my favourite topics right now, it's also one of the first problems I tried to solve.  I wanted to make sure I can do this, because a simple game like mine needs something to keep you engrossed, and I think AI is a big part of that.  First big challenge was finding a way to write the AI.  In my first attempt at the HTML5 version of this, it was literally going to be if/then statements.  I can only imagine the joy I would have had once I got more than a couple of basic concepts in.  I'll be honest that I haven't tried every approach yet, but have found one I liked.  I first played with State machines, which I thoroughly enjoy, here is an example I followed:
This works, but I don't know it's 100% right for my project.  I feel like I will go to the same state from several states, and I think this is where this model will get hard to maintain.  What if I change a condition to go to this state, and it's from 4 states?  
I looked at behaviour trees, but to be honest not a huge amount.  I didn't try it myself, as I was worried that again my situation might get too difficult to maintain with behaviour trees, though it wouldn't suprise me if that's wrong.
I took a look at Apex Utility, mainly just watching their whole youtube series.  It looks very good, and I still may jump over to it, especially if I have issues with performance and debugging:
I found a lot of resources on GOAP.  This sounds much better for what I'm doing.  Write an action, give it requirements and outcomes, then that action is written, completely isolated from your characters, their state, etc, etc:
Out of a couple of GOAP Unity examples I found, this seemed to be clear and easy to follow:
The big problem I found (and would love to still know the answer to this) is it seemed really difficult to interupt an action.  For example, if you've read through the GOAP stuff, imagine your character is very hungry, so the best action is to get food from fridge.  But on the way, ninjas appear.  I couldn't find a clean way in this code to break the food action if ninjas attacked.  I managed it, but hated how I did it.
Which led me to a seemingly simple approach, which ticked all boxes:
With this, I could manipulate it easily to do everything I wanted, including have the AI "sleep", and wake it up, have the clean simple actions, have the weight based decision making.  This is what I've chosen as an AI framework, and so far no restrictions or issues at all with it, though I've been bitten a couple of times by creating a new action, and forgetting to assign it to my players..

What I do have issue with is backing up.  Early last week I imported something, which I really didn't like, so I went to delete it.  Long story short, I deleted everything!  My previous backup was from 4-5 nights earlier, and was 90% AI code.  This was very frustrating, but rather than dwell too much, I used it as a way to streamline my thoughts on the project in whole.  Firstly, I have a tonne of learning to do, a tonne of code to write, and I was going too deep on AI that wasn't going to be necessary to release, like what to do in situations that weren't possible in the first cut of the game.  So I may have lost some code, but gained some focus.  Since then I've worked mainly on other areas, so AI is back to near the starting point in terms of code actually in my project right now.

Graphics
  
Yes, I am awful at that stuff, and this is where my game should really struggle.  But thanks to Unity, thanks to Youtube, it's nowhere near as sucky as it should be.  I can only imagine some people will laugh when they see it, but if you know what I'm capable of outside of Unity... well, I'm happy with what I've acheived.  The concept of scenes is OK, though I'm still fumbling a lot around with the cameras, lighting, terrains, etc.  A simple concept in my head is either done in 5 seconds, or sometimes 2 days, in a much more complex way than I thought it would be.  Some things I haven't been able to do, but to be honest, it's mostly been good.  

Firstly, to make my life easier, I've used a scene where 1m = 1x or 1z.  So I know a player might kick the ball 50m, that's Vector3.Distance = 50f, this seems to work well so far, and makes it very easy in a script.  Next up was a grass like surface.  I used a terrain, and added a grass texture I found.  Graphics people may be laughing at it, but I like the look of it.  I knew as soon as I saw it, that a few line markings, fences, stadiums etc, and this would look great, which I still think.  The characters and animations I got from maximo.com so far.  I'm really not looking forward to trying to do anything that isn't supplied in this area, but we'll see, as I know people get upset if the animation doesn't look great.  I understand, I don't want to give people easy reasons to dismiss my efforts.  The boundary lines were going to do my head in, but I found a link (can't find it now, grrr) that lets you place a transparent picture onto a terrain, it worked brilliantly.  I now have boundary lines, 50m lines, center square, goal squares, and it all looks great.  For fences, I built a bunch of 10m long, thin cubes, and placed them around the boundary line.  Looks good, though I do want to put some gaps in later, and advertising on the remaining.  Like many things, beyond the fence seemed daunting.  I wanted some grass hills, and some stands.  For the hills, I started with rotated cubes going from the ground near the fence, up to a high point.  It was OK, but had problems.  What I really wanted was to raise the terrain into a normal ramp like hill, but it was impossible to do it as I wanted... until I found this article:
That was 100% what I wanted, and gave me really realistic looking hills.  There are even some mild imperfections, exactly as you'd expect given real hills are not a perfect flat surface.  I think they look great so far.  Next up were the stands.  I found a pictture of what I wanted and actually did it in Unity itself.  I tried Blender, but had no idea what I was doing, so used Unity, basically adding levels on top of each other, which is what the picture looked like anyway.  For colours, I downloaded some more textures of asphalt (what the ground was in the picture), corrugated iron for the roof. and brick for the wall.  To be honest, my lack of skill showed up here, as the textures look great as a single tile, or up close, but from a distance all you notice is the repeating patterns in them.  That said, it still looked way better than I thought I'd be capable of.  The last things I got up last night were trees and scoreboard.  Not complete yet, but I just wanted a little something extra before I called it quits, and this was easy to do and looked great.  I had a couple of animations going, but lost those in my backup disaster, so the characters are bland T shaped mocap characters that float to the ball right now.

Gameplay

After I lost my code, I went about some of the starting points of starting a game, like a main menu, and a couple of game choices.  In fact, I went from nothing here and a lot of AI, to nearly no AI, but a way to get all the gameplay options done.  I don't mean all the menu options, I mean click start game, make a choice, click on things for gameplay etc.  It's all very early on, and it looks very bland right now.  As for actually gameplay, I have played a bit with colliders, rigidbodies, physics, etc, and find there is a lot to do here. As an example, because my ball can bounce, and my character is a colider, the player can't pick the ball up, because as soon as they get close, the ball bounces in front of them.  I have (perhaps unwisely) turned off a lot of physics for now.  For the ball flight, I tweaked this code to simulate a kick or handball:
It works really well, and also gave me an insight to coroutines, which I still haven't used elsewhere, but guarantee I'll need to (probably AI before too long).  

As for scripts, there is a game manager script, which stores the state of the game, and can do some updates for UI and gameplay type things.  As an example, I have a 3, 2, 1 countdown on screen before the action starts (may or may not keep this).  Some discs also come out of the graound at some point to allow you to make a choice, I hope this stays.  Each player then has a player script.  On Update the player moves/animates whatever they were doing, and every so often (time depends on the current state and position) AI will refire.  As an example, you could in an action to lead to a pass, but once the ball is kicked, you are no longer leading, but trying to get to where the ball will land (actually to where it will be head height to catch).  Every player also has all the AI scripts attached to them.  It doesn't matter that the full back will probably never kick at goal in my game, they are still a player, and should still have the capability to do so.  At very worst, it would be embarassing if they somehow got the ball in front of goal, but looked to pass it because they weren't taught to kick.  Some of this may hurt performance, but in that case I doubt it as the kick at goal action requires you to have the ball and be close to goal, so there will mainly be a lot of return null with a single if.

That is a big update.  Things will obviously slow down a lot over the next few weeks.  As I said, no official goals this week, as I could end up spending the next 4 nights on a single issue, or perhaps learning to use blender.  Still, I'd like to leave every weekly update with a list of important links I've found.  They are a bit lacking this week, notb because I haven't seen a lot more, just because I've forgotten about them.  But hopefully from now on, I'll keep a better eye on the links I use:

This one is completely new to me, viewed on my train commute this morning, but apart from being a bit quiet and slightly rushed, the first 3 videos in this series are seriously packed with blender info.  I'm looking forward to this series now, who knew 3D was so easy :)  

Not sure I'll use this at all, but perhaps a method to make the terrain hills/other things more low poly, if necessary:

The following are all based on app idea I've had.  It's core functionality is half written in Android Studio, but thought it may be fun to write in Unity too.  Pros are could make very cool special effects for an app.  Cons are it's almost certainly too much to download/startup time for a fairly simple app:

More advanced discussion about mechanim and it's problems, a bit over my head for now:

Half decent story about release time:

Will call it quits there, got to get back to coding this thing.

Monday, September 12, 2016

Game AI (part 1): To exploit or not

Rock, Paper, Scissors.  Imagine we were building the AI for that, how would we do it?  It seems simple at first, randomise the decision, we can't be beat, right?  It is right, statistically we could win or lose against a computer doing this, but over 1000s of games, we will win the same percentage as the computer, it's essentially a no win decision.  It is also an unexploitable AI decision.  No matter how clever we are, we can never find a system to get better than break even in the long run.  This is not fun for humans, we like to be able to beat AI, so how do we dumb down this decision just a little bit?

Lets look firstly at making the decision a whole lot smarter.  Think about this.  After playing this rock, paper, scissors game for 10 minutes, we come to the conclusion it's completely random, so we starting choosing paper every single time, because we just don't care, or perhaps we are trying to work out if it really is just random.  This is no better or worse for the player, because the AI is indeed random.  Our unexploitable AI decision now seems very dumb though, because it should be choosing scissors every single time and winnning.  If you were playing against a human, there is no way the human would randomly choose rock if we had chosen paper 5 times in a row.  So the AI in this case is unexploitable, and completely non-human like.  That can't be good?  So lets add a bit of logic.  If human player chooses paper 4 times in a row, choose scissors, else choose random.  For argument sake, lets say it's also coded that any decision 4 times in a row, on the 5th attempt make the decision to beat that decision on the 5th attempt.  The AI just got a little bit more human, and at the exact same time, is now exploitable.  Once the human works out the AI decision making process, they can make a strategy that exploits the computer.  Once worked out, I would always choose rock 4 times, then on the 5th choose scissors.  Then scissors 3 more times, then paper, etc etc, until we are splitting 4/5ths of the time, and winning 100% of that 5th turn.  In this game, that's a pretty decent level of success.

Again, the human decides instead to just alternate in the exact same order, rock, paper, scissors, rock, paper, etc, etc.  Again another human player would pretty quickly work this out and start exploiting, but how does a computer do that?  Most likely they have to recognise it as a pattern, which we effectively have to program in.  So we program it in, if they chose, rock, then paper, then scissors, we'll choose paper next, to thwart their next decision, which probably rock.  Next instead the human keeps trying scissors, paper, rock (ie. reverse it).  Now, the computer should be able to exploit that.  We could end up with a lot of code, just trying to be more human.  And every bit of logic we add in, makes another part we can exploit.  To go down this route too much further would be recognise a human pattern, exploit it, but then realise we could be exploited back.  The code gets really hairy here.

To go to the nth degree on this, look at this web page:
http://www.nytimes.com/interactive/science/rock-paper-scissors.html?_r=0

In theory this is the machine learning approach to beating us.  When a player does X, and we do Y, our DB, sampled over 1000s of users says their next move is most often Z.  There could probably be a whole book on the approach to using this data to make a great machine learning rock paper scissors, and the machine learning itself could be extremely simple or complex depending on who is driving it.  I think in terms of the one used here, it basically looks over the last 5 decisions made by both players, and matches that up against a patter in the DB of all the other users it played before, and works out what your next decision will be by weight of most common next human decision.  This strategy is creepily good, because humans are actually pretty predictable when playing this random game.  Yes we are trying to exploit, but then so are most humans, and we get caught trying the same exploit.  To be honest, with a decent range of games and opponents that have played, this AI is very human like, and a very smart human like... however, it's still exploitable, because it goes into every game with a set strategy.

Finally, this approach, though very awesome, still says nothing about me personally.  Forget rock, paper, scissors for one second, and think about a generic FPS game.  The programmers have gone to great lengths, and machine learned everything, right down to how fast humans usually respond, lets say 0.3 seconds, and the AI decides to make their decisoin 0.35s, giving the average human a slight edge.  This is great, but if the human happens to be more like 0.4s, we will get slaughtered and likely stop playing.  Likewise, the better players our there are well under 0.2s and they think this game is far too easy.  This seems an ideal time to think about either editable settings, or perhaps going the rubber band theory, allow the AI to adjust it's settings based on previous history.  Of course, the major issue with rubber band theory is the rubber band can be manipulated.  For example, if I play 3 games in a row, and deliberately react 2s for every shot, the AI will have a lot of evidence that I am on the extreme side of slow, and treat me accordingly, how could it not?  So when I go to get a high score/show my friend how I crush this game, I suddenly go back to 0.3s to show them, and suddenly I'm winning the game with amazing ease.  Yes, this theory is exploitable too.  I could probably adjust way quicker with the rubber band to evidence of suddenly improved times, this would make it a lot more human.

I guess it comes down to, the first thing you have to admit with AI, is that it will in some way be exploitable (or be your lifes work), so at that point, you can embrace that fact, and make sure you control just how you want that exploit to be happen for someone to beat your AI.  I'm planning to have a little fun with exploiting in my game.