Objective Cameras

From WiCWiki

Revision as of 11:25, 11 December 2007 by kowalski (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

Contents

Objective cameras.

Once upon a time, in the beginning of the single player campaign, there weren’t any good ways to know where objectives took place on the map. Sometimes, especially if there were more than one objective active at the time, it could be really confusing to know where to go. So it was decided that we should have a camera that showed the player where to go and the Objective camera (aka Ludde Cam) was born. Now we have a camera before almost every primary objective, and in the objectives browser.


Good things to know about objective cameras.

The objective cam is more or less build from key frames. A key frame is a position in the world which the camera will move to. The objective camera starts from its current position and moves to the key frames position or from one key frame to another if there’s more than one. It is possible to set so that the camera starts at a specified point but more about that later.


Objective camera created the debug_viewer way.

The easiest way to make objective cameras is to use the debug_viewer, it will create all the python code that are needed to run the camera. All you have to do after you have saved the camera is to copy past the python code in to the client.py file and call the camera from the server.py file.


To start the Debug Viewer.

Much more info about the ‘Debug_Viewer’ in the chapter about the ‘Debug_Viewer’.


First of all you have to make sure that you have the ‘wic_viewer.py’ in the wic roots python folder (not the map specific ones).


Start the game with –console in the target bar in the wic.exe properties.


C:\wic\WIC.exe –console. Open the console by pressing the button right next to “1” and above the tab button. Write py import wic_viewer and press enter. Then write py wic_viewer.TogglePyViewer() and press enter. Now the debug viewer will start.


Make sure that the ShowObjectiveCamera are set to true.


Image:Objective_Camera_001.jpg


Click on the OBJECTIVE CAMERAS to view the objective camera settings.


Image:Objective_Camera_002.jpg


Save Cameras to file.

Saves the camera to two files a python file and a .foo file in the maps folder. The name of the files is nameOfTheMap_saved_objectivecameras and it’s confusing enough, the maps multiplayer name. The foo file is for the debug_viewer to use, you don’t have to deal with it, like ever. The py file contains all the python code that you need to create the camera. All you have to do is to copy it to the client.py file.


Create new Camera.

Create a new objective camera that we can add key frames too.


CurrentPosition.

Print the current positions of the camera.


CurrentLookAt

The position the camera looks at.


Create a new camera.

To create a new camera, click the ‘CreateNewCamera’ alternative in the list. This will create a camera with a default name ObjCam0 or something similar.


Click on the newly created camera to see all the camera settings.


Image:Objective_Camera_003.jpg


Play.

Test play the objective camera.


RemoveCam.

Removes the objective camera and all the key frames it has.


Add new key frame

Adds a new key frame to the camera. A key frame is a position the camera will move to and a point to look at.


Cam Settings.
Camera Type.
Some predefined camera settings you can use.


Use Grab on Release.
Decides if the camera should stay at the end position of the camera or jump back to the position the camera had when the camera started. Default is ‘False’/0 and means it won’t grab.


EndDelayTime.
Decides how long the camera should stay at the last key frame before it releases the camera. You can change the time with the arrow keys.


MaxSpeed.
Sets the max speed of the camera.


MaxAcceleration.
Sets the max acceleration of the camera.


Add Key frames.

To add new key frames you just have to find some nice camera views and click on ‘Add new Key frame’. When you click ‘Add new key frame’ the current position of the camera and in what direction it is facing, ‘look at’, will be saved to the key frame and that key frame will be added to the camera. The default name is Keyframe0 (or Keyframe1,2,3 etc). The key frames will be added in the same order you added them in, i.e. the first key frame you add will be the first stop for the camera.

When you click on a key frame in the debug_viewer, the camera will jump to the position of that frame. That makes it easy to edit the camera later.

When a key frame is selected there will be a green marker which shows the camera position in the world and the selected key frames name.

Click on the new key frame to view the key frame settings.

Image:Objective_Camera_004.jpg


Remove Key frame.

Remove the key frame from the camera.


Update Key frame.

Update key frames position and look at position to the cameras current position.

The look at position will be shown as a string with the text ‘update key frame’.


Move Key frame Up.

Move the key frame up in the key frame list. The key frames name will change for example; if you move KeyFrame3 to position 2…it will change name to KeyFrame2.


Move Key frame down.

Move the key frame down in the key frame list. The key frames name will change as in the example above.


Key frame Settings. Settings you can do on the key frame.


DelayTime.
How long the camera will stay at the key frame before it moves on to the next frame.


CloseToLimit.
How close to the key frames position the camera has to be to count as completed.


DistanceToLookAt.
How close to the cameras position the look at should be.


UseGotoNow.
If the camera should move to the key frame position or jump to it directly. It is 0 by default and that means it will move to the position.


UseLookAtNow.
If the camera should rotates toward the look at or snap to it. Default is 0 which means it won’t snap.




The Village objective camera

So let us make the objective camera for the village event.


We start by finding a camera view that we feel works, like the one in the image below. Click on ‘Add new Key frame’ to add the key frame to the camera.


Image:Objective_Camera_005.jpg


Lets test the camera we just created. Click on “play” and watch the camera. If you are not happy with the camera, tweak it by changing the position, look at or the camera speed.


When you are satisfied with your camera click on ‘Save Cameras to file’. Now you should have a multiplayermapname_ saved_objectivecameras.py file, in this case a do_Ruins_saved_objectivecameras.py file, in the wic\maps folder. And, once again, it’s the maps multiplayer name.


The code in the do_Ruins_saved_objectivecameras.py file will look something like this.

def ObjCam0Camera( aIsBrowserCamera = True ):
    ObjCam0 = ObjectiveCameraEx( 'ObjCamVillage', aIsBrowserCamera )
    p = ObjCam0.AddPoint( Position(994.98, 137.25, 1088.85), Position(988.93, 115.74, 1038.00), 2.0, 10.0 )
    ObjCam0.SetEndDelayTime( 3.000 )
    ObjCam0.SetCameraMaxSpeed( 120.000 )
    ObjCam0.SetCameraMaxAcceleration( 100.000 )
    ObjCam0.Play( )
    return ObjCam0

Now you can copy the camera that you just created to the client.py in maps\europeTest\python\ folder.

It can be a good idea to change the default name ObjCam0Camera to something that is easy to remember and makes more sense, for example: ObjCamVillage


There is a Command Point in the Village objective, and we want it to be shown in the objective camera. To make the Command Point visible during the camera we have to add one line of code in the ObjCamVillage function.

ObjCam0.AddCommandPoints( [ "CP_Village" ] )

ObjCam0 is the name of the objective camera that we shall add the Command Point to.

The parameter is a list of Command Point names. The list can have one or more Command Points.


The ObjCamVillage code should now look something like this.


##---------------------------------------------------------------
#---------------------------  Village ---------------------------       


def ObjCamVillage( aIsBrowserCamera = True ):
    ObjCam0 = ObjectiveCameraEx( 'ObjCamVillage', aIsBrowserCamera )
    p = ObjCam0.AddPoint( Position(994.98, 137.25, 1088.85), Position(988.93, 115.74, 1038.00), 2.0, 10.0 )
    ObjCam0.SetEndDelayTime( 3.000 )
    ObjCam0.SetCameraMaxSpeed( 120.000 )
    ObjCam0.SetCameraMaxAcceleration( 100.000 )
    ObjCam0.AddCommandPoints( [ "CP_Village" ] ) 
    ObjCam0.Play( )
    return ObjCam0

Let's look at the code more closely.

def ObjCamVillage( aIsBrowserCamera = True ):

Define the function with the argument aIsBrowerCamera = True. It is ‘True’ by default and it should be assigned to ’True’ if you want the camera to be a browser camera as well.


ObjCam0 = ObjectiveCameraEx( 'ObjCamVillage', aIsBrowserCamera )

Creates the objective camera object with the name ‘ObjCamVillage’ and posts the aIsBrowserCamera, the variable that decides if it is a browser camera or not and that we’ve assigned in the previous line.


p = ObjCam0.AddPoint( Position(994.98, 137.25, 1088.85), Position(988.93, 115.74, 1038.00), 2.0, 10.0 )

Add a key frame to the camera.


ObjCam0.SetEndDelayTime( 3.000 )

This will make the camera stay 3 seconds at the last key frame.


ObjCam0.SetCameraMaxSpeed( 120.000 )

Set the cameras max speed to 120.


ObjCam0.SetCameraMaxAcceleration( 100.000 )

Set the cameras max acceleration to 100.


ObjCam0.AddCommandPoints( [ "CP_Village" ] )

Add so that the “CP_Village” command point will be visible in the camera.


ObjCam0.Play( )

Start the objective camera.


return ObjCam0

This line of code returns the camera object.

Objective cameras in python.

We must use the ClientCommand (or StartClientCamera, but more about that soon) to start the cameras because they are executed on the client side. The first parameter is the camera functions name from the client.py file and must be a string.


To start the camera we can do like this.

ClientCommand('ObjCamVillage', False )


- The first parameter is the name of the objective camera function in the client.py file as a string.

- The second parameter decides if the camera should be played in “letter box” format. We use the same function to create both the objective camera and the camera in the objectives browser. The camera function is made to suit the browser cam, which doesn’t use the letter box format, so if we want to use the letter box format for the objective cam we have to change the parameter here. ‘False’ means we will have the letter box format and ‘True’ means no letter box.


There is another command you can use to start a camera – StartClientCamera. This is a special function to start objective cameras with, that will make all the players units immortal during the camera.

StartClientCamera( 'ObjCamVillage', False )

The parameters are the same as the ClientCommand.


If you have added a Command Point to make it visible in the camera it also has to be set to active otherwise it will not show. This is the code to make the Command Point active.

You can write this code anywhere as long as it is after the Command Points have been created, but we usually do it in server.py.

SetCommandPointActive( 'CP_Village', True )

-The first parameter is the name of the Command Point.

-The second parameter decides if the Command Point will be activated or deactivated.


def VillageCam( ):
    # Start the objective camera for the village objective. We want the command point to be visible
    # in the camera so we set it to active and then shows a message box.
    queVillageCam = ActionQueue( 'queVillageCam' )        
    queVillageCam.AddFunction( SetCommandPointActive, 'CP_Village', True )
    queVillageCam.AddFunction( StartClientCamera, 'ObjCamVillage', False )
    queVillageCam.Execute( )  

    # Setup reactions for what to do if/when the player click esc or the cam is done.
    RE_OnCustomEvent( 'END_OF_CUTSCENE', Action( PostEvent, 'VillageCamEnd' ) )
    RE_OnCustomEvent( 'SKIP_CUTSCENE', Action( PostEvent, 'END_OF_CUTSCENE' ) )          

Trigger when the camera is finished.


The camera can post two events, 'END_OF_CUTSCENE' when the camera is finished and 'SKIP_CUTSCENE' if the player press escape during the camera.


If you want to trigger something after the camera is finished, you can do like this:

RE_OnCustomEvent( 'END_OF_CUTSCENE', Action( PostEvent, 'VillageCamEnd' ) )
RE_OnCustomEvent( 'SKIP_CUTSCENE', Action( PostEvent, 'END_OF_CUTSCENE' ) )

The first line of code will post the event ‘VillageCamEnd’ if the camera ends without being escaped. The second line of code will post the event 'END_OF_CUTSCENE' that will trigger the first line of code which will post the event ‘VillageCamEnd’.


This way it does not matter if the player sees though the whole camera or skips it, it will always post the 'VillageCamEnd' event.

Appendix

To get the objective cameras to works we add the camera code generated with the debug viewer to the client.py file in this case in the StartClientCamera function. We call the StartClientCamera function from the VillageCam function in the server.py file.


Changed files in this chapter:

Server.py

Client.py


Changes in the server.py file.


def VillageCam( ):

    [More code here.]

    queVillageCam.AddFunction( SetCommandPointActive, 'CP_Village', True )
    queVillageCam.AddFunction( StartClientCamera, 'ObjCamVillage', False )
    queVillageCam.AddMessageBox( 'e1_1', 101 ) 

    [More code here.]


def VillageCam( ):
    DebugMessage( "VillageCam::" )

    # Create the units that are defending the village.
    allunits.Village( )

    # Start the objective camera for the village objective. We want the command point to be visible
    # in the camera so we set it to active and then shows a message box.
    queVillageCam = ActionQueue( 'queVillageCam' )        
    queVillageCam.AddFunction( SetCommandPointActive, 'CP_Village', True )
    queVillageCam.AddFunction( StartClientCamera, 'ObjCamVillage', False )
    queVillageCam.AddMessageBox( 'e1_1', 101 )
    queVillageCam.Execute( )  

    # Setup reactions for what to do if/when the player click esc or the cam is done.
    RE_OnCustomEvent( 'END_OF_CUTSCENE', Action( PostEvent, 'VillageCamEnd' ) )
    RE_OnCustomEvent( 'SKIP_CUTSCENE', Action( PostEvent, 'END_OF_CUTSCENE' ) )


Changes in the client.py file.


[More code here.]

##---------------------------------------------------------------
#---------------------------  Village ---------------------------      
def ObjCamVillage( aIsBrowserCamera = True ):
    ObjCam0 = ObjectiveCameraEx( 'ObjCamVillage', aIsBrowserCamera )
    p = ObjCam0.AddPoint( Position(994.983, 137.251, 1088.856), Position(988.932, 115.749, 1038.000), 2.000, 10.000 )
    ObjCam0.SetEndDelayTime( 3.000 )
    ObjCam0.SetCameraMaxSpeed( 120.000 )
    ObjCam0.SetCameraMaxAcceleration( 100.000 )
    ObjCam0.AddCommandPoints( [ "CP_Village" ] )
    ObjCam0.Play( )
    return ObjCam0

##---------------------------------------------------------------
#-------------------------  RescueArty  -------------------------   
def ObjCamRescueArty( aIsBrowserCamera = True ):
    ObjCam2 = ObjectiveCameraEx( 'ObjCamRescueArty', aIsBrowserCamera )
    p = ObjCam2.AddPoint( Position(734.680, 137.148, 768.070), Position(711.929, 127.262, 735.337), 2.000, 10.000 )
    ObjCam2.SetEndDelayTime( 3.000 )
    ObjCam2.SetCameraMaxSpeed( 120.000 )
    ObjCam2.SetCameraMaxAcceleration( 100.000 )
    ObjCam2.UseEndGrab( False )
    ObjCam2.Play()
    return ObjCam2


Chapter 14: Debug Viewer < > Chapter 16: Timers
Personal tools
User Created Content