Sunday, 28 February 2016

Programmatically handling button clicks

Since Unity 5 we have buttons that the designer can hard-wire to component (no-arg) functions. Usually this may be a good thing. But not always.

  • Sometimes you want to bind a button dynamically.
  • Or you may want to pass a parameter to the target function
  • Or just add code to a button.
A handy script allowing you to bind a button to a message dynamically. By default the message is delivered to the named object, this can be customised for delivering to children or ancestors. If no object name is specified, delivery uses the button object as a starting point (useful to implicitly deliver upwards to a 'panel controller')

Variants show how to load a numbered level upon clicking a button:

Also check this Q&A for how to remove listeners and more.

Saturday, 27 February 2016

PUN shooter #13 - Experimenting with assets and level design

Textured Assets

From a workflow point of view, textured assets are a drag. Here's an example using an arbitrary scene downloaded from the Unity Store.
  • Web player export over 10 minutes (maybe) 15 (My laptop is 5 years old; happy birthday)
  • Player size inflated from ~4mb to 180mb. This won't load successfully never mind slow.
Stripping textures off the asset put size down to 24mb but this unsurprisingly doesn't look great.

Not this time.

Muddling through level design

I had a crazy level design session today. The bottom line, though, is that I was trying to move too fast whereas, when it comes to level design, patience literally pays off.

Since there are plenty things that can go wrong when integrating new assets, trying to put together too much stuff at once is a recipe for disaster. On the other hand, taking the time to do things correctly is helpful because working elements are easy to reuse.

Unity notes

I've been toying with a little utility to work with materials. Lessons learned:

  • The names of materials are distinct from their filenames. Gets amusing after you renamed materials programatically.
  • Not putting third party assets in version control is dangerous.

Friday, 26 February 2016

PUN shooter #12 - Playtest debrief

A couple of days back I tested the game with friends around the world (literally). Overall we had a little fun and the following requests came out:

  • Jumping - I'm guessing this came from the design of the map which kind of forced a (non jumping) player to run anti-clockwise.
  • Classic FPS controls - A predictable request.
  • Frame rate and Ping - Because we had one player in Brazil whose connection is apparently much slower than ours, but we don't have a way to quantify that.
  • In-game sound control
  • Chat feature - I'm not taking this too seriously though I suspect that I don't really have a choice in this area.
I also noted that players go missing from the leaderboards; worse, it looks like race conditions may occur when trying to start a battle, so two players may each be trying to start their own instead of playing together.

Tuesday, 23 February 2016

A bird eye view of back-end services for games a.k.a Parse Alternatives

As I look set to release my first multiplayer games within 2 months time (much less for the web builds) I've been looking at Parse alternatives - in other words, Back-end-as-a-service (BaaS) with Unity support.

What are we looking at today? Services that fit the following description:
  • Free up to X
  • Cloud (server-side) storage and code.
  • Unity aware
  • Easy to use and well documented
  • No-nonsense approach to storing data, JSON oriented.
  • Free up to 1m API calls/month.
  • Server-side custom Java
Looks as flexible as Gamedonia; the downside for me would be Java instead of Javascript but this is very contingent to... me not wanting to run Eclipse on a crammed laptop.

Note: AppWarp looks to be part of App42 as an offering more specifically geared towards game development.

BrainCloud
  • JSON
  • Mongo
  • Free up to 100 DAU (~3000 MAU; $30 => ultd DAU and 6m API calls )
BrainCloud has an emphasis on statistics and monetisation. This on top of looking well documented and flexible enough, makes it at least as (if not more) attractive as GameDonia (below).

  • NoSQL DB (Mongo)
  • Free up to 10k MAU 
  • Server-side custom JS
I'm not entirely bought in because I don't understand how to store global/match properties.

Maybe just a first impression, Gamedonia looks easy to use and their docs are really straightforward.

Heroic Labs
  • Server side JS
  • Free up to 10K MAU
Offer looks comprehensive.
Pitch: social features, advanced leaderboards.

  • Server side JS
  • Free, mostly
References
A little terminology

MAU = Monthly Active Users.
DAU = Daly Active Users

Monday, 22 February 2016

PUN shooter #11 - Battle Royale 2/2 (implementation)

The first steps towards implementing a new game mode have been mundane:
  • Add buttons in the menu
  • Add a static field indicating which game mode we are playing (for now, all modes go to the same scene. Will cause quirks later but... later).
  • Disable the KO sequence that would normally bring a player back to the menu. Part of the idea of the battle royale (a la Counter Strike I guess) is that defeated players do not respawn. The crux is not to let them re-enter the same room they just lost in; in the meantime, encouraging them to remain "part of the game" in interesting ways is on the plan.
The next step was to implement the other side of a 'battle mode': a battle should not start until all players are onboard. Took more time than I expected.

Replacing materials

In battle mode, defeated players do not disappear. Instead, they become ghosts. This required replacing all materials and I discovered something unexpected while doing this: Renderer.materials returns a copy of the materials array. This means that replacing a material in that array is ineffective. For changes to take effect, the returned array must be re-assigned to renderer.materials.

RPC note

Sometimes writing 'networked features' can be as easy as tagging a method [PunRPC] and calling PhotonView.RPC(...) but there's a catch: before that even works, the other side must have a copy of the invoked component. At times this may catch you off-guard. For example, the KO sequence in my case is handled by a component local to the KO'd player but the effects of KO should be visible everywhere. an RPC into a [PunRPC]'d function of that component will fail.

Photon Notes

<> Avatar rotation felt 'snappy' (going in brusque increments like a clock hand). Reducing interpolation speed makes rotation smoother (too slow isn't good either since the rotation lag becomes too obvious)

<> Photon provides player 'names' which are the nicknames we're after for our leaderboards. Network-wise it appears that setting the player name via PhotonNetwork.playerName is the way to go (read them normally via PhotonPlayer.name)

<> After all wanted players have joined a match, close the room via PhotonNetwork.room.open = false, PhotonNetwork.room.visible = false

Preventing confusion between battle rooms and the 'main' room.

With several game modes, letting players join whatever room available may cause errors. For now I resolved this by having all 'survival' players entering/creating a named, while battle rooms are randomly created.

Sunday, 21 February 2016

Pun Shooter #9 - Animation? Shoot...

Since yesterday I've been wondering how we should add shooting animations to our game. One route is I ask the original asset author to create them. Another is I try to do this with my appointed go-to Blender animator. Finally, we might animate shooting procedurally.

Back to the source?

Right now I'm unsure about the asset author's availability. Another thing to consider is the number of animations we might need. Say, what would please me?

  • Light gun (single)
  • Light gun (dual)
  • Medium (single handed) automatic weapon
  • Heavy weapon (Bazooka, Missile launcher)

Plus, at least some of these (light/medium) should have a running variant. Yea that's a lot.


The Blender way?

How about ordering from my Blender animator? Chill but I'm not sure how to do a Unity (fbx) <=> Blender (.blend/.fbx) round trip. I can export somewhat usable rigs and models from Unity, but so far no luck getting them to play nice with the original Mecanim setup.

(Bear in mind I'm trying to add animations to an existing set, not developing a new set from scratch).

Procedural animation


I did some preliminary testing with procedurally animating the little guys' arms. Initially it was frustrating  but, if nothing else overriding transforms in LateUpdate (this has to be done at every frame) does work.

References

A Unity blog post addresses animation assets - quite possibly out of date.

PUN shooter #10 - Multiplayer matches 1/2 (design considerations)

It looks like I'm settling on a name for the current game mode : practice. This nails the issue - the experience provided by just logging in and shooting anybody else that happens to be logged in or not is inconsequential. So I decided to implement a "Battle Royale" mode but let's just call it matches.

Improvised matches

An improvised match is when several players happen (randomly or maybe not so randomly) to be online and decide to start a match together. This is expected to work best when you and your friends get online to play together.

Later I imagine that private matches could be made available. Private matches can work with secret rooms but I visualise it better as having a list of connected friends, and starting pretty much as described above.

Scheduled matches

Scheduled matches are expected to work better as a means to get a limited audience together. The idea is that, at any point in time there may not be enough people logged in to start a fun match. But if there are matches say, every 1 hour or every 20 minutes, people are encouraged to come at the appointed time. Although it may not fully beat a lack of players (which is what I expect initially) it can help.

Maybe it would work better if people can pre-register but for now I will allow a 15-30 minutes window to pre-register, which essentially is trying to do the same thing.

Improvised matches look like more work but I feel that players may like them more so I will start with that.