Tutorial Preventing Camera-work Breakdown that Results from Multi-player Lag

ShadowTek

New Member
Reaction score
23
The Problem

Any camera field adjustment that is applied over a period of time is subject to being broken if an instance of multi-player lag occurs, where a “Waiting for players...” countdown dialog appears. This can completely screw up a cinematic to the point where it is just absolutely ruined.


An Example of the Problem

As an example of what I am referring to, I will describe a scene that I once created.

The camera started out at a height of around 5000. The angle of attack was facing directly down (270*). The first application of a timed camera field adjustment was to change the z offset of the camera over 10 seconds so that the camera descended from its position, high in the sky, all the way down to the ground.

Once the camera was close to ground level, then the angle of attack was changed so that the camera tilted upward 90 degrees, from looking straight down to looking straight ahead. At that point, characters would enter the scene, and begin the perform in front of the camera.

The problem I was having was that a moment of lag would frequently hit during the descent of the camera. (Some aspect of the scene was apparently CPU intensive.) After the lag box went away, and the game resumed, the camera would not descend any further beyond that point. It just sat there until the next triggered camera field adjustment took place. Of course, the next adjustment was to turn upward and look head-on at the actors. But when the camera did this while it was still high in the sky, then it would simply turn upward and look out across the horizon. The scene would begin to play out below, but you couldn't see anything except the stupid sky! lol


A Partial Solution

The easiest way to make sure that your camera-work continues to move through your originally planned travel path is to make an instantaneous “follow-up” action after any timed action.
Code:
Actions
        Player Group - Pick every player in (All players) and do (Actions)
            Loop - Actions
                Camera - Set (Picked player)'s camera Angle of attack to 331.00 over 3.00 seconds
        Wait 3.00 game-time seconds
        Player Group - Pick every player in (All players) and do (Actions)
            Loop - Actions
                Camera - Set (Picked player)'s camera Angle of attack to 331.00 over 0.00 seconds

Since the “follow-up” action occurs instantly, then there isn't any opportunity for it to break. In this way, even if lag is experienced during those 3 seconds, the “follow-up” camera action will be applied, and the camera will eventually end up at its desired destination after the Wait action is finished.

The advantage of this is that it is very easy to integrate into all your triggers. The disadvantage is that you still end up with a camera that remains “stuck” motionless until the end of the Wait action. If the camera field value is being applied over a long period of time, then the result will be very disruptive to the flow of the overall scene.


An Unbreakable Solution

The only unbreakable method which I have found for dealing with this problem is to use periodic time events to continuously advance the camera fields, in a manner similar to using triggers to move units or special effects across a playing field.


If a moment of lag hits while you are using this method, then the camera will will just pick right back up where it left off and proceed to complete the application of the camera value to the very end. However, the disadvantage is that it requires a lot more trigger work to get the job done.


Calculating Values

Let's say that I want to change my camera's angle of attack from 45 to 331 over 3 seconds. If it wasn't for this cursed lag problem, then we could take care of this with one simple action:
Code:
Camera - Set (Picked player)'s camera Angle of attack to 331.00 over 3.00 seconds

But we're going to have to do this the hard way, so lets get started.

First, you need make note what the current camera field value is, and set a real variable to that value. In this example, I will be starting with an angle of attack of 45. So:
Code:
Set CameraFields[1] = 45.00

Second, you need to decide what you want the final value for that field will be. Then, you need to decide the length of time over which the value will be applied.

I need to cover a “distance” of 74 degrees (45 + (360 - 331)) over 3 seconds. Now, if I am using a periodic that expires after 0.01 seconds, then this means that I will be using close to 300 repetitions of the trigger (3 / 0.01) over which I will cover this “distance” of 74 degrees. If I divide 74 by 300, then I can see that I will be changing my angle of attack by approximately 0.25 degrees each time the trigger is fired. So, my angle of attack will change by 74 degrees with exactly 296 executions of this periodic trigger.

The camera field will be modified by periodically setting it to equal the value of the real variable that you set the original camera field value to. We first start out by creating our new trigger (that is initially off, of course) and a periodic event to go with it:
Code:
Camera Timer 1
    Events
        Time - Every 0.01 seconds of game time
    Conditions
    Actions

If this were a simple addition or subtraction of a distance between two points, then we could use something simple to calculate the modifications to the camera field, like this:
Code:
Camera Timer 1
    Events
        Time - Every 0.01 seconds of game time
    Conditions
    Actions
        Set CameraFields[1] = (CameraFields[1] - 0.25)
        Player Group - Pick every player in (All players) and do (Actions)
            Loop - Actions
                Camera - Set (Picked player)'s camera Angle of attack to CameraFields[1] over 0.00 seconds

But we are dealing with angles in this example, so we have to take into account the fact that all subtractions of this real variable that go below zero will need to be handled in a manner so that “-1” actually becomes 359 (as in degrees). So, we need to throw something in there that will reset the value of the variable when it gets close to that point.

In this case, figuring out the exact value that we need to make the change at is easy, since we are starting and ending with nice round numbers, and the increments of change (0.25) are easy to calculate in one's head. :D We will need to reset the value of this variable to 360 when it reaches 0. So, let's throw in an “if/then” action to take care of that:
Code:
Camera Timer 1
    Events
        Time - Every 0.01 seconds of game time
    Conditions
    Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                CameraFields[1] Equal to 0.00
            Then - Actions
                Set CameraFields[1] = 360.00
            Else - Actions
        Set CameraFields[1] = (CameraFields[1] - 0.25)
        Player Group - Pick every player in (All players) and do (Actions)
            Loop - Actions
                Camera - Set (Picked player)'s camera Angle of attack to CameraFields[1] over 0.00 seconds

If we leave the trigger in its current condition, then the camera will just keep going end-over-end endlessly, so let's add an “if/then” that will stop the trigger when the camera field reaches the desired value:
Code:
Camera Timer 1
    Events
        Time - Every 0.01 seconds of game time
    Conditions
    Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                CameraFields[1] Equal to 0.00
            Then - Actions
                Set CameraFields[1] = 360.00
            Else - Actions
        Set CameraFields[1] = (CameraFields[1] - 0.25)
        Player Group - Pick every player in (All players) and do (Actions)
            Loop - Actions
                Camera - Set (Picked player)'s camera Angle of attack to CameraFields[1] over 0.00 seconds
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                CameraFields[1] Equal to 331.00
            Then - Actions
                Trigger - Turn off (This trigger)
            Else - Actions

Make sure to get your calculations right for the “if/then” conditions, or “else” it won't work.

Now, this example has just been for modifying a single camera field. As you might imagine, things get a little more complicated when you start modifying many different camera fields simultaneously. Of course, if you want to apply a whole camera object, then every value will need to set in this manner at the same time!


Conclusions

Using the simple solution of instantaneous “follow-up” actions should be integrated into all camera-work for multi-player games. This will, at least, prevent a total breakdown of the overall travel-path of the camera when relying on successive individual field adjustments to reach a planned destination. Of course, any time that a complete camera object is applied, then all values will be specified, and the cinematic will “back on track”. Of course, the timed application of the camera object might get broken by lag also, so remember to use an instantaneous “follow-up” action for that as well!

When you start to consider the amount of work that you would have to through in order to use the periodic adjustment method to apply all the values for an entire camera object (which could otherwise be handled with a single trigger action), then it's time to decide how much effort that you are willing to put into it.

Sometimes, it is only necessary to use the periodic method during certain moments of intense special effects or during some other event that tends to regularly result in lag. Scenes that only involve the timed modification of a single camera field (as in the previous example) are much easier to handle in this way, as opposed to the complexity of scenes that involve several simultaneous field adjustments.

Hopefully, Blizzard will develop a fix for this problem some day. But for now, we will have to decide which combination of techniques achieves the best balance of time invested versus results achieved when planning or reworking any cinematic for multi-player games.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top