How to implent cut scenes?
by Alexander B · in Torque 3D Professional · 02/22/2010 (6:31 am) · 48 replies
I want to have cutscenes in my game. Not ingame cutscenes like what GMK and Verve does but acual pre-made cutscenes.
What I want to do is get the cutsecene in an ogg file, make a trigger that activates the cutscene ingame and if possible goes to the next mission or the main menu.
I relize that I will probaly have to use theora but I don't really understand it or how to use it.
What I want to do is get the cutsecene in an ogg file, make a trigger that activates the cutscene ingame and if possible goes to the next mission or the main menu.
I relize that I will probaly have to use theora but I don't really understand it or how to use it.
#22
You can place the GuiTheoraCtrl on your toplevel control in the Gui Editor. The control is found in the "Images" category. Simply create a new control (leave the default GuiControl as the toplevel control) called 'CutsceneGui' in the GuiEditor, place the GuiTheoraCtrl where you want it, and save it. The relevant properties on the gui are set in script.
02/27/2010 (7:43 am)
Sorry for the late comeback; that wasn't planned.You can place the GuiTheoraCtrl on your toplevel control in the Gui Editor. The control is found in the "Images" category. Simply create a new control (leave the default GuiControl as the toplevel control) called 'CutsceneGui' in the GuiEditor, place the GuiTheoraCtrl where you want it, and save it. The relevant properties on the gui are set in script.
#23
First off, with the theora GUI, can i make multiple theora GUI'S so I can play more then 1 video as the theora GUI only allows 1 video. Also if possible how would I make sure multiple triggers use the theora GUI I want them to use.
Secondly the video plays in the left hand corner. Has this got to do with resolution or can I make it fit the whole screen?
Thirdly It crashes once the video is done. Probaly because this comes up in the console: checkCutsceneFinished: Unknown command.
Also as soon as the cutscene is finished I want it to either 1. Go back to the mission. 2. Load the next missions. 3. Go to the main menu
Lastly how do I get sound on the .ogg videos? I have no idea what to download from vorbis.com
I can't thank you enough for this and I will definatley give you the game for free as well as have you in credits if you want.
02/27/2010 (11:40 pm)
It works!!!!! Although its not over yet hehe. First off, with the theora GUI, can i make multiple theora GUI'S so I can play more then 1 video as the theora GUI only allows 1 video. Also if possible how would I make sure multiple triggers use the theora GUI I want them to use.
Secondly the video plays in the left hand corner. Has this got to do with resolution or can I make it fit the whole screen?
Thirdly It crashes once the video is done. Probaly because this comes up in the console: checkCutsceneFinished: Unknown command.
Also as soon as the cutscene is finished I want it to either 1. Go back to the mission. 2. Load the next missions. 3. Go to the main menu
Lastly how do I get sound on the .ogg videos? I have no idea what to download from vorbis.com
I can't thank you enough for this and I will definatley give you the game for free as well as have you in credits if you want.
#24
You can have multiple GuiTheoraCtrls (even running at the same time) but I'm guessing this isn't what you actually want. Simply assign different filenames to the "theoraFile" property in script to play different files at different times in the same control. The "startCutscene" function does that.
The no-sound problem is probably the sound init bug that I fixed for 1.1. It caused Vorbis audio to fail initialization with some videos. This is fixed in the current 1.1 which, however, does not help you immediately as the release will still take a few weeks to be finalized.
The crash problem is definitely a bug though I'm pretty sure this is also fixed for 1.1. If this works for you, it would be great if you could send me the video file in question so I can give it a test run here.
However, I'm pretty sure the problems you are seeing are already fixed in 1.1.
As for checkCutsceneFinished, make sure the function definition is in the proper place and executed.
To go back to the mission, don't disconnect() in the first place. Either just leave the game running or pause it by setting $timeScale=0.
Then pass the choice along to checkCutsceneFinished as appropriate and do something like this:
//Edit: $timeAdvance must be $timeScale here; $timeAdvance=0 will have no effect.
02/28/2010 (4:37 am)
Glad it works so far.You can have multiple GuiTheoraCtrls (even running at the same time) but I'm guessing this isn't what you actually want. Simply assign different filenames to the "theoraFile" property in script to play different files at different times in the same control. The "startCutscene" function does that.
The no-sound problem is probably the sound init bug that I fixed for 1.1. It caused Vorbis audio to fail initialization with some videos. This is fixed in the current 1.1 which, however, does not help you immediately as the release will still take a few weeks to be finalized.
The crash problem is definitely a bug though I'm pretty sure this is also fixed for 1.1. If this works for you, it would be great if you could send me the video file in question so I can give it a test run here.
However, I'm pretty sure the problems you are seeing are already fixed in 1.1.
As for checkCutsceneFinished, make sure the function definition is in the proper place and executed.
To go back to the mission, don't disconnect() in the first place. Either just leave the game running or pause it by setting $timeScale=0.
Then pass the choice along to checkCutsceneFinished as appropriate and do something like this:
function checkCutsceneFinished()
{
if( CutsceneGui->video.isPlaybackDone() )
{
switch$( CutsceneGui.afterVideoEndsAction )
{
case "NextLevel":
StartLevel( CutsceneGui.nextLevelName );
case "MainMenu":
diconnect();
case "Continue":
Canvas.setContent( PlayGui );
}
}
else
schedule( 10, 0, "checkCutsceneFinished" );
}//Edit: $timeAdvance must be $timeScale here; $timeAdvance=0 will have no effect.
#25
For the function checkCutsceneFinished() code you posted. I only put in nextlevel, mainmenu or continue so not all of them right?
As for sound, the ogg video I am using I converted with theora goodies and it always crashes when it gets up to the sound bit so I don't know how to get an ogg video with sound.
02/28/2010 (12:42 pm)
Do i put $timeScale=0 in that function? Also to have multiple cutscenes I am going to have to make multiple triggers correct?For the function checkCutsceneFinished() code you posted. I only put in nextlevel, mainmenu or continue so not all of them right?
As for sound, the ogg video I am using I converted with theora goodies and it always crashes when it gets up to the sound bit so I don't know how to get an ogg video with sound.
#26
If you have multiple places in your mission that go to different cutscenes, then yes, you need multiple triggers. You can use the same datablock on each, though, and simply make the cutscene file a dynamic property on each trigger, i.e. assign a dynamic property "cutsceneFile" to each trigger and then in the trigger function do
You could also use the same scheme to control the behavior for what to do after the cutscene has played by adding another dynamic property "afterCutsceneAction" to each trigger and set it to one of "NextLevel", "MainMenu", or "Continue" and adapt your scripts (add a "nextLevelName" dynamic property to the trigger for when you select "NextLevel" as the action):
The crash is most definitely the sound init bug I fixed for 1.1. Unfortunately, that requires a source code change.
One thing you could do is to strip the audio for now and use it without sound. Then when 1.1 final is released, you can put the sound back in. I'm sorry for not being able to offer an immediate solution here.
//Edit:
BTW, make sure to restore $timeScale in checkCutsceneFinished
//Edit:
Also, be aware that the simple $timeScale trick above only works in what basically is a single-player game, i.e. where the server runs in-process with the client.
//Edit:
You probably also need to set all schedule calls to zero delay in order for them to execute with $timeScale=0. Otherwise, they'll remain stuck in the event queue.
02/28/2010 (12:55 pm)
Stopping simulation has to happen when you go on to play a cutscene, i.e. in "startCutscene" (instead of disconnecting).function startCutscene( %theoraFile )
{
// Pause simulation.
$timeScale = 0;If you have multiple places in your mission that go to different cutscenes, then yes, you need multiple triggers. You can use the same datablock on each, though, and simply make the cutscene file a dynamic property on each trigger, i.e. assign a dynamic property "cutsceneFile" to each trigger and then in the trigger function do
function CutsceneTriggerData::onEnterTrigger( %this, %trigger, %obj )
{
// Schedule execution of cutscene playback of the given Theora video file.
schedule( 0, 0, "startCutscene", %trigger.cutsceneFile );
}You could also use the same scheme to control the behavior for what to do after the cutscene has played by adding another dynamic property "afterCutsceneAction" to each trigger and set it to one of "NextLevel", "MainMenu", or "Continue" and adapt your scripts (add a "nextLevelName" dynamic property to the trigger for when you select "NextLevel" as the action):
function CutsceneTriggerData::onEnterTrigger( %this, %trigger, %obj )
{
// Schedule execution of cutscene playback of the given Theora video file.
schedule( 0, 0, "startCutscene",
%trigger.cutsceneFile,
%trigger.afterCutsceneAction,
%trigger.nextLevelName
);
}
function startCutscene( %theoraFile, %nextAction, %nextLevelName )
{
// Pause simulation.
$timeScale = 0;
// Set video file to play.
CutsceneGui->video.theoraFile = %theoraFile;
CutsceneGui->video.playOnWake = true;
CutsceneGui.afterVideoEndsAction = %nextAction;
CutsceneGui.nextLevelName = %nextLevelName;
// Put up CutsceneGui.
Canvas.setContent( CutsceneGui );
schedule( 0, 0, "checkCutsceneFinished" );
}The crash is most definitely the sound init bug I fixed for 1.1. Unfortunately, that requires a source code change.
One thing you could do is to strip the audio for now and use it without sound. Then when 1.1 final is released, you can put the sound back in. I'm sorry for not being able to offer an immediate solution here.
//Edit:
BTW, make sure to restore $timeScale in checkCutsceneFinished
function checkCutsceneFinished()
{
if( CutsceneGui->video.isPlaybackDone() )
{
$timeScale = 1;
switch$( CutsceneGui.afterVideoEndsAction )
{
case "NextLevel":
StartLevel( CutsceneGui.nextLevelName );
case "MainMenu":
diconnect();
case "Continue":
Canvas.setContent( PlayGui );
}
}
else
schedule( 0, 0, "checkCutsceneFinished" );
}//Edit:
Also, be aware that the simple $timeScale trick above only works in what basically is a single-player game, i.e. where the server runs in-process with the client.
//Edit:
You probably also need to set all schedule calls to zero delay in order for them to execute with $timeScale=0. Otherwise, they'll remain stuck in the event queue.
#27
Also rene, I am sorry but I am a bit lost. My last posts have been a bit to compicated for there own good so I will sum up exactly what I need.
I need the trigger to either launch the next mission or go to the main menu as I now do not need to pause the game. So bassicly, can you please tell me the sripts for both of them as that is pretty much all I need.
Also once everything is figured out we (or just me) can package this up into a resource as this could help a lot of people.
03/01/2010 (1:55 am)
SOUND IS WORKING!!!!! I used this other converter and now sound is fully working. This is what I used if anyone needs it http://v2v.cc/~j/ffmpeg2theora/download.htmlAlso rene, I am sorry but I am a bit lost. My last posts have been a bit to compicated for there own good so I will sum up exactly what I need.
I need the trigger to either launch the next mission or go to the main menu as I now do not need to pause the game. So bassicly, can you please tell me the sripts for both of them as that is pretty much all I need.
Also once everything is figured out we (or just me) can package this up into a resource as this could help a lot of people.
#28
The scripts in your case would pretty much boil down to:
03/02/2010 (1:22 am)
Cool, glad it's all working for you.The scripts in your case would pretty much boil down to:
function CutsceneTriggerData::onEnterTrigger( %this, %trigger, %obj )
{
// Schedule execution of cutscene playback of the given Theora video file.
schedule( 0, 0, "startCutscene",
%trigger.cutsceneFile,
%trigger.afterCutsceneAction,
%trigger.nextLevelName
);
}
function startCutscene( %theoraFile, %nextAction, %nextLevelName )
{
// Stop game.
disconnect();
// Set video file to play.
CutsceneGui->video.theoraFile = %theoraFile;
CutsceneGui->video.playOnWake = true;
CutsceneGui.afterVideoEndsAction = %nextAction;
CutsceneGui.nextLevelName = %nextLevelName;
// Put up CutsceneGui.
Canvas.setContent( CutsceneGui );
schedule( 100, 0, "checkCutsceneFinished" );
}
function checkCutsceneFinished()
{
if( CutsceneGui->video.isPlaybackDone() )
{
switch$( CutsceneGui.afterVideoEndsAction )
{
case "NextLevel":
StartLevel( CutsceneGui.nextLevelName );
case "MainMenu":
Canvas.setContent( MainMenuGui );
}
}
else
schedule( 100, 0, "checkCutsceneFinished" );
}
#29
datablock TriggerData (CutsceneTriggerData)
{
tickPeriodMS = 100;
};
function CutsceneTriggerData::onEnterTrigger( %this, %trigger, %obj )
{
// Schedule execution of cutscene playback of the given Theora video file.
schedule( 0, 0, "startCutscene",
art/videos/fire1.ogv,
disconnect(),
town.mis
);
}
However when I go into the trigger it crashes. I may be doing something wrong tho.
03/02/2010 (2:02 am)
Here is what my trigger looks like:datablock TriggerData (CutsceneTriggerData)
{
tickPeriodMS = 100;
};
function CutsceneTriggerData::onEnterTrigger( %this, %trigger, %obj )
{
// Schedule execution of cutscene playback of the given Theora video file.
schedule( 0, 0, "startCutscene",
art/videos/fire1.ogv,
disconnect(),
town.mis
);
}
However when I go into the trigger it crashes. I may be doing something wrong tho.
#30
03/02/2010 (2:07 am)
You need to put parenthesis around the arguments to schedule. In your onEnterTrigger function you are calling disconnect() correctly which brings down the client and server in-midst of gameplay logic--a certain crash.
#31
art/videos/fire1.ogv,
echo("test"),
town.mis
I don't get a crash and it doesn't load the next mission and I get this error in the console art/gui/CutsceneGui.gui (61): Unable to find object: '0' attempting to call function 'isPlaybackDone'
03/02/2010 (2:18 am)
Here it is now: art/videos/fire1.ogv,
echo("test"),
town.mis
I don't get a crash and it doesn't load the next mission and I get this error in the console art/gui/CutsceneGui.gui (61): Unable to find object: '0' attempting to call function 'isPlaybackDone'
#32
Re schedule:
The arguments all must be given as strings. What you want to do here is defer the execution of a piece of code by passing to schedule a time at which to execute it, the name of the function name to call (or object+method combination), and all the arguments. Later, the function is called with the arguments.
So:
[code]
schedule( 0, 0, "startCutscene", "art/videos/fire1.ogv", "NextLevel", "levels/town.mis" );
[/code
Also be aware that %nextAction must be one of "NextLevel" or "MainMenu".
Re video not found:
Set internalName=video on GuiTheoraCtrl as stated above.
03/02/2010 (2:34 am)
Re schedule:
The arguments all must be given as strings. What you want to do here is defer the execution of a piece of code by passing to schedule a time at which to execute it, the name of the function name to call (or object+method combination), and all the arguments. Later, the function is called with the arguments.
So:
[code]
schedule( 0, 0, "startCutscene", "art/videos/fire1.ogv", "NextLevel", "levels/town.mis" );
[/code
Also be aware that %nextAction must be one of "NextLevel" or "MainMenu".
Re video not found:
Set internalName=video on GuiTheoraCtrl as stated above.
#33
datablock TriggerData (CutsceneTriggerData)
{
tickPeriodMS = 100;
};
function CutsceneTriggerData::onEnterTrigger( %this, %trigger, %obj )
{
// Schedule execution of cutscene playback of the given Theora video file.
schedule( 0, 0, "startCutscene", "art/videos/fire1.ogv", "NextLevel", "levels/town.mis" );
}
03/02/2010 (2:54 am)
We are half a step forward. When i go into the trigger it shows like one second of the clip then launches the next level. Here is my trigger code:datablock TriggerData (CutsceneTriggerData)
{
tickPeriodMS = 100;
};
function CutsceneTriggerData::onEnterTrigger( %this, %trigger, %obj )
{
// Schedule execution of cutscene playback of the given Theora video file.
schedule( 0, 0, "startCutscene", "art/videos/fire1.ogv", "NextLevel", "levels/town.mis" );
}
#34
Sorry, sort of lost track of this one.
Are you sure you have checkCutsceneFinished like it is above?
03/03/2010 (4:24 pm)
Sorry, sort of lost track of this one.
Are you sure you have checkCutsceneFinished like it is above?
#35
03/03/2010 (9:36 pm)
Sorry, must of done something wrong as i just re-did it and it works perfectly. Anyway last thing I need to do is know how to have multiple cutscenes.
#36
Simply use the onEnterTrigger function I included in post #28 and assign the "cutsceneFile", "afterCutsceneAction", and "nextLevelName" values as dynamic properties to the triggers. This will then play different cutscenes depending on which trigger you are walking into.
03/04/2010 (6:40 am)
Simply use the onEnterTrigger function I included in post #28 and assign the "cutsceneFile", "afterCutsceneAction", and "nextLevelName" values as dynamic properties to the triggers. This will then play different cutscenes depending on which trigger you are walking into.
#37
03/04/2010 (11:37 pm)
Sorry, the cutscene has stopped working :( It loads the next level about 1 second into the cutscene then when the next level is on it keeps the music. However a simple way around this is making the video go for a set duration with the trigger and change the duration on each trigger. If you have a better idea please tell me as this is all I can think of but I have no idea how to do it.
#38
03/07/2010 (10:15 pm)
Bump
#39
Thanks and I hope there is an obvious solution to the problems I am having.
03/13/2010 (12:45 am)
Rene, I hope you are reading this, I have uploaded my GUI file and my trigger file on my site. Here is the link: http://mmorpglord.com/cutscene/Cutscene.rarThanks and I hope there is an obvious solution to the problems I am having.
#40
From what you describe, it would appear that isPlaybackDone falsely signals true in the first (delayed) call to checkCutsceneFinished and thus triggers the transition. The music keeps playing as without setting stopOnSleep, the video will not be stopped.
If that is indeed what happens, it would seem to indicate a bug in the video player code.
Can you send me the video file you are using?
03/13/2010 (3:41 am)
That pretty much looks the way it should.From what you describe, it would appear that isPlaybackDone falsely signals true in the first (delayed) call to checkCutsceneFinished and thus triggers the transition. The music keeps playing as without setting stopOnSleep, the video will not be stopped.
If that is indeed what happens, it would seem to indicate a bug in the video player code.
Can you send me the video file you are using?
Torque Owner Alexander B