Twitter
Sunday
Sep182011

Scripted Cutscenes

This is an unscheduled post, but we couldn't quite keep this to ourselves. Something we've known we've needed for a while was a way to call scripted cutscenes in the prototype. This morning we decided it was time to stop putting it off and start putting it together. 

2 hours later, we had out cutscene manger in place and our first scripted cutscene in the game. Something we would never have expected to happen.

This is really down to all the hard work we've been doing in building a re-usable framework, but it still surprised us how easy it was to put together. 

This isn't going to be a big 'how to' - but we just wanted to share a little of what the code looks like for a cutscene. The scenario his that the player approaches an NPC and the cutscene triggers. In the cutscene the NPC and the player share some lines, turn to a boat, walk to it and jump on. The boat then moves off with the two character onboard. 

And this is the script:

IEnumerator mainCutscene()
{
	lookTargetObjectPos = MrShaw.transform.position;
	StartCoroutine("lookTarget");
	
	ddsl.moveObjToObj(myCam, GameObject.Find("MRSHAWcamera1"), 3f);

	ddsl.rotateObjToObj(player,MrShaw,0.5f);

	ui.showPanel("textBox");

	textBox.setName("Mr. Shaw");
	textBox.setTextCS("Yar *name*. You ready to go to coast town?");
	ddsl.playAnimObj(MrShaw, "TalkMain1");

	while(textBox.displayingText) yield return new WaitForEndOfFrame();

	textBox.setName(globals.instance.playerDB.playerName);
	textBox.setTextCS("Lets go!");
	ddsl.playAnimObj(player, "TalkYes");

	while(textBox.displayingText) yield return new WaitForEndOfFrame();

	ui.hidePanel("textBox");		

	ddsl.moveObjToObj(myCam, GameObject.Find("MRSHAWcamera2"), 3f);

	ddsl.rotateObjToObj(player,boat,0.5f);
	yield return new WaitForSeconds(0.25f);

	ddsl.rotateObjToObj(MrShaw,boat,0.5f);
	yield return new WaitForSeconds(0.25f);
	
	ddsl.moveObjToObj(player, GameObject.Find("MRSHAWPlayerboatNode"),1.5f);
	ddsl.playAnimObj(player, "Run");
	yield return new WaitForSeconds(0.25f);

	ddsl.moveObjToObj(MrShaw, GameObject.Find("MRSHAWShawboatNode"),1.5f);
	ddsl.playAnimObj(MrShaw, "Run");
	yield return new WaitForSeconds(0.25f);
	
	ddsl.playAnimObj(player, "Jump");
	yield return new WaitForSeconds(0.25f);

	ddsl.playAnimObj(MrShaw, "Jump");
	yield return new WaitForSeconds(1f);
	
	player.transform.parent = boat.transform;
	MrShaw.transform.parent = boat.transform;
	
	ddsl.moveObjToObj(myCam, GameObject.Find("MRSHAWcamera3"), 3f);
	ddsl.moveObjToObj(boat, GameObject.Find("MRSHAWBoatNode1"), 6f);
	
	yield return new WaitForSeconds(5f);
	
	Messenger.Broadcast("cameraFade", 0.5f, 1f);
}	

 

Going through the code you should get some idea of how easy it is to set up little story scenes. Here we're manipulating four actors, the Player, 'Mr. Shaw', the Boat, and the Camera. These actors then use nodes in the scene to set them in the right position for the cutscene. 

Obviously there's a lot of backend code in there. All the ddsl calls are to our scripting language we built into Unity and we have code that handles text boxes and the movement of UI elements. But we hope this will give you a little inspiration if you're thinking about how to add simple scripted cutscene to your game. 

PrintView Printer Friendly Version

EmailEmail Article to Friend

References (1)

References allow you to track sources for this article, as well as articles that were written in response to this article.
  • Response
    [...]Doki Doki Games - Blog - Scripted Cutscenes[...]

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>
« Doki Doki Bloki - Soundtrack | Main | Using a Server to keep Game Time in Sync »