Showing posts with label Unity 3D. Show all posts
Showing posts with label Unity 3D. Show all posts

Wednesday, 17 February 2016

PUN shooter #4 - More drama

In the last 4 sessions I added the following:

  • A game menu
  • UI elements to 'dramatise' the re-spawn process
  • Sound effects and music
  • A credits section.
Nothing too hard or complex here, even though getting all this done has been a long day's work.


You can try the game [here]

Tuesday, 16 February 2016

PUN shooter #3 - Footprints and footsteps.

In the past couple of days I worked on scripts for footprints and footsteps. Also, proxies didn't play animation.

<> Velocity and collisions may report incorrectly for kinematic bodies updated over the network.

The tricky part was getting a good enough answer to the simple question, "is the avatar walking". This breaks down into "is the avatar moving" and "is the avatar grounded".


Since collisions report inaccurately we can't use OnCollisionStay() to tell us an avatar is grounded. Instead, use raycasting.

Surprisingly, speed reported via position sampling proved inaccurate enough that I had to average readings over time to get acceptable results.

Sunday, 14 February 2016

PUN shooter #2 - Player prefabs, Web Player and WebGL

Customising player prefabs (~2 hours)

Today I focused on providing a different character for each player.
My asset provides Mecanim prefabs. Let's not convert everything to legacy and use this. No need to setup a state machine. Mecanim's Animator does support Play(string).

My setup uses model/view decoupling. So what I send to PhotonNetwork.Instantiate() is the model prefab (containing the logic), then I select a view prefab (containing the mesh and animations) and instantiate that locally.

So, how to make this view the same across the network? Well. PhotonNewtork.Instantiate() allows an object[] as parameter. This you can retrieve from PhotonView as InstantiationData upon handling OnPhotonInstantiate. 

WebGL build (~2 hours)

For better and for worse, it's the future.
In the meantime, WebGL is new tech. Neither Photon nor UNET totally play nice with it
(See Q&A here).
  • Photon chat will generate an error (comment out the code is okay... if you don't use Photon chat I guess).
  • Uncheck 'run in background'
  • Uncheck 'strip engine code'
At the time of writing, my Photon/WebGL builds crash in Safari and Chrome.
Also, a WebGL build takes 20 minutes on my 6 years old laptop. 

Never mind bugs that may or may not be fixable, it would take a fair amount of automation to smooth this enough for daily or even weekly builds so I guess I'll stick to the deprecated (before the new stuff even works?) web player.

Web Player (~20 minutes)

You can try it [here] (bring your friends)

Saturday, 13 February 2016

Pun shooter #1 - Shooting

In the past couple of days I've been making a basic shooter. Caveats.

Transform sync doesn't work. Why?

  • If using a rigid body, ensure kinematic is on for the proxy (but you should still see some sync regardless.
  • Remember to add the NetworkTransformView to PhotonView.
Collisions not working

Kinematic proxies aren't good at generating collisions. Why? Because if you receive say, 10 positions per second, and an object bounces on the remote, the proxy may interpolate towards the new direction without picking up the actual collision.



I realised this while dealing with physical projectiles. This time around I decided to Network-Instantiate projectiles but adding physics locally via script attached to the bullet prefab.

Ghost bullets

What we create with PhotonNetwork.Instantiate(...) must be destroyed with PhotonNetwork.Destroy(...). A symptom of doing otherwise (for example, destroy all local copies of an object) is that entering clients will "replay" previously instantiated objects.

Input methods

After I put a little game together we got to try it on two laptops simultaneously. One of the laptops didn't respond to key strokes. Investigating, we found that a foreign input method was conflicting with game input.