Friday, 14 June 2013

Developing Multiplayer fight controls in Real-Time


Was just working on the control system for the fighting engine of the upcoming World of Fighters game. And, I have to say, it is so much cool being able to code in real-time. Seriously, I wasted so many years of my life, compiling, linking, deploying, refreshing. Just being able to code and see what happens is amazing.

I'll give you three scenarios I was just working through. Remember, for all these changes, I didn't have to compile/re-deploy any code, I just hit command-s to save and the code just updated in real-time as I was experimenting.

Punching and Kicking
First up was how the action buttons should work. Should they issue an attack as soon as they are pressed or when they're released? I didn't know which one to go with, so I just experimented with the two options until I found one I liked.

Modified the auto-generated .js file from the UI Editor to use onPress rather than onRelease.


Moving
Ok for moving it was a more difficult choice. Originally I had it so that the player moved a step towards or away from their opponent if the left or right button was first pressed. However, this required tapping several times in order to get close to your opponent, which is very un-natural compared to how all other fighting games operated.

Move towards your opponent on a right press.

To solve this, I instead marked a flag when the arrow buttons were pressed, then unmarked it when it was released. Then in my update loop, I would move the player accordingly.


The problem with this approach however was that it increased the data being sent across the multiplayer network. So to reduce this packet, I put in a timer, which updated the key press state once every x number of milliseconds. With x being a value I experimented with until I was happy with the response time.


So rather than the client telling the server that the right or left arrow was pressed every update loop, it instead sent out the message every 250ms.


Camera
I had a few issues when setting up the camera for the fight. I wanted to have it focus in-between the two players fighting, however I had a bug in my calculation. So first up to solve this, again in real-time, I inserted a marker in the map, and moved it to point at different parts of my calculation, until I visually saw the part of the maths that was incorrect.


Once that was solved, I then played around with the camera distance values depending on how close or far away the players were from each other.

A multiplier of 2.5 seemed about right.


Cool huh?
I remember watching WWDC ten few years ago when Steve Jobs introduced the new linker improvements for XCode.

Well now ten years later, you can not only get rid of linking, but you pretty much zero-everything apart from debugging out... damn you debugging.
Well at least with zero-stop/compile/run, debugging is a lot improved as it totally reduces the need to having to re-setup scenarios for the problem states to occur. Which is doubly awesome for multiplayer gaming, as those problem states are so much harder to set up.

Note: we're still currently in beta, but it's public so you're more than welcome to give our tools a go and  start modifying your code/ui/design or assets in real-time :)

3 comments:

  1. A+ for this article. A lot more complicated than animation.

    This game looks wicked. Want to play it

    ReplyDelete
  2. There are presently a scope of Arcade modes from form 6 - Mini-Zone, Quick Match or Sniper Training. You can have an irregular choice or pick which you need to play. Clicks Test

    ReplyDelete
  3. Great article Lot's of information to Read...Great Man Keep Posting and update to People..Thanks the boxing tonight

    ReplyDelete