Forum rules - please read before posting.

3D First person - Interrupting conversations. How would you suggest doing it?

edited March 2019 in Technical Q&A

Hello folks,

This is how conversations currently work in my game:

At the moment, I fire off a 'Talk to' action list and everything plays out. This comes with a problem which so far I've ignored and I'd like to start addressing, which is the player can move away while conversations are occuring.

The easy solution would be to freeze the player when a conversation starts, and unfreeze them at the end.

I'm down with that, but, would like to try a more interesting solution which would be if the player starts to move away, to stop the conversation action list and fire up a new action list.

I'm seeing the logic something like this:

• Throw 'talk to' at NPC
• Check how far the player is away in units
• If close enough play main conversation action list
else
• If not close enough play 'not close enough' conversation action list ("Huh? I can't hear you!")

• While main conversation action list is playing:
• If player moves away a certain amount of units, stop the current action list and start a different 'player leaving' action list

Does that sound sensible? I'm planning to handle this in a custom script unless there is a way of perhaps setting this up inside a single action list?

Thanks!

Comments

  • If not close enough play 'not close enough' conversation action list ("Huh? I can't hear you!")

    This can be done by reading a Vector3 variable that's set to the vector between the Hotspot and the Player.

    Create a new Vector3 Global Variable named e.g. "Player to Hotspot". You'll have to set its value through script at the moment the Hotspot is triggered, but I'm assuming you have a hook for that already given your custom interaction system:

    Vector3 vectorValue = KickStarter.player.transform.position - myHotspot.transform.position;
    GlobalVariables.SetVector3Value (id, vectorValue);
    

    Where "myHotspot" is the Hotspot you're interacting with, and "id" is the ID number of the Vector3 Global Variable.

    In the ActionList, you can then use the Variable: Check Action to determine if this variable's magnitude (which would be the distance between the two) is within a given threshold.

    If player moves away a certain amount of units, stop the current action list and start a different 'player leaving' action list

    This'd be more tricky, but if you updated the vector's value every frame then you could run a similar check on a loop while the "speaking" Actions are run.

  • @ChrisIceBox Thanks Chris. Instead of putting the logic into the action list and having to duplicate the setup for all NPC action lists, I've opted to have it handled in a reusable script. First results are promising!

    Are there ways in script to know if an action list has been started, is currently running, and is completed?

  • AreActionsRunning()

    This might be what I'm looking for!

  • That bool check was exactly what I needed. Again, thanks to AC what I thought might take me a week or so to develop ended up taking 3 hours.

  • edited March 2019

    Hah, looks great!

    AreActionsRunning() can be used to check if any Actions at all are running, but if you're looking to check the state of specific ActionLists you can hook into the OnBeginActionList and OnEndActionList custom events.

  • edited March 2019

    @ChrisIceBox

    In my case I'm using AreActionsRunning() on a particular action list variable. So like:

    public ActionList testActionlist;
    
    void update()
    {
    print(testActionlist.AreActionsRunning());
    }
    

    Early tests suggest it just reports the state of the particular action list, and not any others that might be happening at the same time. Am I ok using it in this way?

  • AreActionsRunning() is a fairly intensive operation, particularly if the ActionList has many Actions involved. If you're looking to check if a particular list is running, I'd recommend events instead of an Update method.

    The equivalent code, using events:

    public ActionList testActionList;
    private bool isRunning;
    
    
    private void OnEnable ()
    {
        EventManager.OnBeginActionList += OnBeginActionList;
        EventManager.OnEndActionList += OnEndActionList;
    }
    
    
    private void OnDisable ()
    {
        EventManager.OnBeginActionList -= OnBeginActionList;
        EventManager.OnEndActionList -= OnEndActionList;
    }
    
    
    private void OnBeginActionList (ActionList actionList, ActionListAsset actionListAsset, int startingIndex, bool isSkipping)
    {
        if (actionList == testActionList)
        {
            isRunning = true;
        }
    }
    
    
    private void OnEndActionList (ActionList actionList, ActionListAsset actionListAsset, bool isSkipping)
    {
        if (actionList == testActionList)
        {
            isRunning = false;
        }
    }
    
  • @ChrisIceBox Thank you sir. In that case I'll migrate over to events today. :)

  • edited March 2019

    @ChrisIceBox I'm getting a lack of definition for .OnEndActionList via EventManager. OnBeginActionList however auto-completes fine inside Visual Studio.

    AC Ver# 1.66.2

  • Ah! Update needed. Didn't realise I wasn't running the latest AC version.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.