Page 1 of 1

Skillcheck Modifiers - animation.

Posted: Mon Aug 05, 2024 4:03 am
by Mithrithnogg
Hello, I've recently purchased Unity's Dialogue System for Unity and I already checked out the skill check modifier for conversations. But I was wondering how hard would it be to add a D20 animation to each roll?
I'm working on a 3D game but I already got 20 - 2D animations for each roll, i.e. D1, D2, D3.... to D20. And I'm kind of new to coding so I have no idea where to start.

I suppose that my main question is how much of the base code or the example would I have to modify in order for an animation to be displayed? And would that break the dialogue system?
Thanks in advance.

And as a side-note. I'm actually referring to a dice system like Baldur's Gate 3's.

Re: Skillcheck Modifiers - animation.

Posted: Mon Aug 05, 2024 8:47 am
by Tony Li
Hi,

You should never need to modify any base code in the Dialogue System. It's designed to allow you to extend its capabilities without having to directly modify it. There are two common ways to extend the Dialogue System. They both make a C# method available to the Dialogue System.

The first way is to register your C# method with Lua. Then you can use it in a conversation dialogue entry's Script or Conditions fields.

The second way -- which I recommend for the d20 animations -- is to write a sequencer command. (More info: Cutscene Sequences) Then you can use your custom sequencer command in a dialogue entry's Sequence field.

Let's assume you have a script in your scene (perhaps on a GameObject named "DiceManager" or something) that has a method RollD20(result), where result is the die roll value. Maybe that script looks something like:

Code: Select all

using UnityEngine;
public class DiceManager : MonoBehaviour
{
    public Animator dieAnimator;
    
    public void RollD20(int result)
    {
        dieAnimator.SetInteger("Result", result);
        dieAnimator.SetTrigger("Roll");
    }
}
where the dieAnimator variable has been assigned in the Inspector to an animator controller that looks something like:

rollAnimator.png
rollAnimator.png (31.21 KiB) Viewed 398 times

To create the sequencer command, you'd create a script that looks like:

Code: Select all

namespace PixelCrushers.DialogueSystem.SequencerCommands
{
    public class SequencerCommandRollD20 : SequencerCommand
    {
        private void Awake()
        {
            int result = GetParameterAsInt(0);
            FindFirstObjectByType<DiceManager>().RollD20(result);
            Stop();
        }
    }
}

Then use it like this to show a specific die roll:

rollCommand1.png
rollCommand1.png (10.61 KiB) Viewed 398 times

Or like this to roll a random value and store that value in a Dialogue System variable named "result":

rollCommand2.png
rollCommand2.png (27.25 KiB) Viewed 398 times


You can also access this variable in your own C# code using:

Code: Select all

int result = DialogueLua.GetVariable("result").asInt;