Page 1 of 1

NPC actions And movements

Posted: Tue Jul 17, 2018 2:14 am
by Amine33
Hello :)
  I would like to ask if there is a way to control NPC actions And his movements

Simple example

At the point A he sits and after 10 seconds rises from his place and goes :arrow: to point B and dance and after the end of the dance back to the point A

And I want Thank you for everything

Re: NPC actions And movements

Posted: Tue Jul 17, 2018 8:46 am
by Tony Li
Hello,

Yes. Use a cutscene sequence. In the Dialogue System, cutscene sequences are text commands, such as "AnimatorPlay(Dance)". Text commands allow you to stay in the flow of writing your dialogue. But you can also use interactive timeline editors such as Unity Timeline or SLATE.

You can play a sequence directly from a Dialogue System Trigger, or in a conversation's dialogue entry node. For example, the node could be:
  • Dialogue Text: "I'm going to rest a little and then dance."
  • Sequence:

    Code: Select all

    AnimatorPlay(Sit);
    AnimatorPlay(Stand)@10;
    AnimatorPlay(Walk)@11;
    MoveTo(Point B,,1)@11;
    AnimatorPlay(Dance)@12;
    AnimatorPlay(Walk)@14;
    MoveTo(Point A,,1)@14;
    AnimatorPlay(Idle)@15

Re: NPC actions And movements

Posted: Tue Jul 17, 2018 2:50 pm
by Amine33
Thank you so much this helped me a lot but I have a strange problem When NPC moves to a point
I use Dialogye system Trigger And Sequnce # https://ibb.co/mwjLwy #



This is an example of the problem that is facing me
https://files.fm/u/j75vc7fa#/view/Video ... 1.wmv;play

Re: NPC actions And movements

Posted: Tue Jul 17, 2018 8:05 pm
by Tony Li
Hi,

It looks like the problem is that the NPC isn't facing the direction that he is moving. To fix this, use the LookAt() sequencer command to make him face his destination. For example:

Code: Select all

AnimatorPlay(Stand)@10;
AnimatorPlay(Walk)@11;
LookAt(Point B,,0.5)@11;
MoveTo(Point B,,1)@11;
AnimatorPlay(Dance)@12;
AnimatorPlay(Walk)@14;
LookAt(Point A,,0.5)@14;
MoveTo(Point A,,1)@14;
AnimatorPlay(Idle)@15
(I added LookAt() commands.)

Sequences can be more sophisticated, too. "How To Write Sequences" explains different ways that you can write sequencer commands. For example, here is another way to handle the timing:

Code: Select all

Delay(10)->Message(Ready);
AnimatorPlayWait(Stand)@Message(Ready)->Message(Stood);
AnimatorPlay(Walk)@Message(Stood);
LookAt(Point B,,0.5)@Message(Stood);
MoveTo(Point B,,1)@Message(Stood)->Message(Arrived_B);
AnimatorPlayWait(Dance)@Message(Arrived_B)->Message(Danced);
AnimatorPlay(Walk)@Message(Danced);
LookAt(Point A,,0.5)@Message(Danced);
MoveTo(Point A,,1)@Message(Danced)->Message(Arrived_A);
AnimatorPlay(Idle)@Message(Arrived_A)
This may look more complicated, but it takes care of the timing so you don't have to figure out how long each animation clip is.

If you want to control the NPC's movement through a controller script, you can write a custom sequencer command. For example, say you write a custom sequencer command called NavigateTo(). Then you could use a sequence like this:

Code: Select all

AnimatorPlay(Stand)@10;
NavigateTo(Point B)->Message(Arrived_B);
AnimatorPlayWait(Dance)@Message(Arrived_B)->Message(Danced);
NavigateTo(Point A)@Message(Danced)->Message(Arrived_A);
AnimatorPlay(Idle)@Message(Arrived_A)
If these get too long and complicated, you can use an interactive editor like Timeline or SLATE. Then your Sequence field can just be, for example:

Code: Select all

SLATE(Dance_Routine)
But of course this means you must also use an additional tool such as Timeline or SLATE.

Re: NPC actions And movements

Posted: Wed Jul 18, 2018 12:23 am
by Amine33
Thanks A Lot for the help and information you provide me


But so far I have not been able to deal with this problem :(


When added Moveto command... NPC Walk in this strange way
https://files.fm/u/8qgebfed#/view/1.wmv;play

And When I delete Moveto command He walks in a natural way

https://files.fm/u/hj4c3j6z#/view/2.wmv;play

Re: NPC actions And movements

Posted: Wed Jul 18, 2018 9:20 am
by Tony Li
It looks like your animation may have root motion. (In other words, the animation itself makes the NPC move.) In this case, you don't need the MoveTo() command, which also moves the NPC. You only need to point the NPC in the correct direction.

If you delete the MoveTo() commands, what issues remain to get it working the way you want?

If you get totally stuck, please feel free to send an example to tony (at) pixelcrushers.com. I'll be happy to take a look.

Re: NPC actions And movements

Posted: Wed Jul 18, 2018 4:16 pm
by Amine33
I found what i can do with Dialogue System ...More Than What I want
Thanks Very Much For Your Help

Re: NPC actions And movements

Posted: Wed Jul 18, 2018 5:20 pm
by Tony Li
Glad to help.