Search Unity

Creating interactive 'cutscenes'

Discussion in 'Scripting' started by TheBlackBox, Mar 22, 2018.

  1. TheBlackBox

    TheBlackBox

    Joined:
    Jan 13, 2014
    Posts:
    33
    Hi!

    Currently working on a project and I'm just looking for an opinion on how to make an interactive 'cutscene' of sorts.

    To better explain what I mean by interactive cutscene, I'll outline what I intend to do.

    The player will be able to walk around freely whilst a character is showing them around - this will involve the character moving, playing audio (for the voice acting) and potentially changing from looking at the player to looking at a different object every so often.

    However sometimes the NPC won't be able to continue to the next part of the scene because the player isn't listening, for example the NPC says "look up for me real quick" awaiting the player's response, potentially playing different voice lines such as "erm, yeah that's just up there please..."

    -------------

    At first I figured I'd create some sort of Coroutine that utilised WaitUntil() but then I figured that would be a variable mess - especially for more extensive scenes.

    I've been recently thinking about using the Animator and utilising Animation Events, but then figured that may be harder to use along with the potential stopping/starting whilst waiting for player input.

    I haven't read into it - but would the Timeline system be of use?

    Anybody have any input into how this is typically done in games? I'd appreciate any insight - thanks!
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    This isn't actually help for your issue, but I just want to point out that players generally hate cutscenes, especially ones where they have to pay attention and do something in response to instructions. Generally the only interaction players want with a cutscene is the ability to skip it quickly.
     
    SparrowGS likes this.
  3. TheBlackBox

    TheBlackBox

    Joined:
    Jan 13, 2014
    Posts:
    33
    Yeah I get that, but I'm using this type of cutscene as a tutorial to teach the players how to play and ease them into the game world.

    It's also for a school project, there isn't a plan for actual release just yet - I'm merely trying to show a variety of skills in a final product.
     
  4. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    Your coroutine idea seems fine, since you can track the starting value of the player's input very easily and then move along in your tutorial sequence.

    Code (csharp):
    1.  
    2. UI.ChangeText("Use your mouse to look around.");
    3. PlayAudio("PleaseLookUp.wav");
    4.  
    5. float startingPitch = player.pitch;
    6. float reminderTime = 0f;
    7.  
    8. while(player.pitch - startingPitch < 45)
    9. {
    10.    reminderTime += Time.deltaTime;
    11.  
    12.    if(reminderTime >= 5f)
    13.    {
    14.        reminderTime = 0f;
    15.  
    16.        PlayAudio("DudeHurryUp.wav");
    17.    }
    18.  
    19.    yield return null;
    20. }
    21.  
    22. // move on to the next step
    23.  
    I wouldn't use it for an actual cutscene scripting though.
     
  5. TheBlackBox

    TheBlackBox

    Joined:
    Jan 13, 2014
    Posts:
    33
    I figured as much. I'm just worried about efficiency with this method. Would it end up becoming one giant Coroutine? Surely there's a much cleaner approach...

    I guess I'll have to give it a shot though, thanks :)
     
  6. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,336
    For what it's worth, I've tried using Timeline for this, and it doesn't feel very appropriate, as pausing in the middle of the Timeline to wait for player input isn't very well supported.

    Using Timeline would essentially mean replacing the parts of your cutscene that are not wait-for-correct-input with Timelines.
     
    Sluggy and TheBlackBox like this.
  7. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    At the end of the day, you have to sample for input and do some things, so I doubt you'll find a more "efficient" approach. You can always break it up into smaller, discrete coroutine methods and chain them.
     
  8. Diablokiller999

    Diablokiller999

    Joined:
    Dec 8, 2019
    Posts:
    6
    FWIW I would use a state machine on that object that has a OnTriggerConditionMet function, which just waits for that trigger to change to the next state in a Vector or something. Now just implement a new state for each animationstep, that plays an animation which Animation End event triggers State Machines OnTriggerConditionMet callback.
    This can also be an object like a target, that sends a trigger to the State Machine.

    Otherwise I would just chain animations together in the animation controller and the transitions listen to an OnTriggerEvent fired by a callback. Conditions are interchangeable and can be anything from looking at a target, hitting a target, reaching a triggerpoint or answering a question.