Forum rules - please read before posting.

check npc charstate

hi Chris, I want to find out how can I know if NPC is in talking or walking state? in actionlist or in code? thanks again

Comments

  • You can access the NPC's isTalking property and IsMovingAlongPath function to check these states.

    See the Manual's "Character scripting" chapter, and the Scripting guide's Char class for details on accessing character information through script.

  • Thanks chris. Can i use char.charstate to check the character state ? Like this:
    if(_char.charstate==AC.charstate.idle)
    i used this but always return true. Even if the character is in talk or walk state. Thanks again
  • Characters can walk and talk independently, so charState can't be used to check if a character is talking.

    The charState variable should be set Move when walking, though. An alternative would be to check their moveSpeed is over a set threshold, i.e.:

    if (_char.MoveSpeed > 0.01f)
    
  • Thanks a lot chris. i used isTalking but same result. always returns false
  • I can't recreate such an issue. What is your AC version, and are you using AC's regular speech system for dialogue?

  • edited May 2022

    I'm using 1.73.5, I updated to the latest version but then my project got a few errors and I decided to revert to 1.73.5 that was best for me, but for now, I want to play custom animations to characters when they're not talking or walking (in idle mode) I created a custom actionlist but this is my problem now, I used same charstate function that I said earlier for the player and its works good but for NPCs its not. i used charstate and isTalking but none of them works for NPCs. and yes I use regular speech system. i will test more solutions. thanks again Chris. have a good day

  • An alternative to using isTalking would be to hook into the OnStartSpeech and OnStopSpeech custom events, in a script attached to the character:

    private void OnEnable ()
    {
        EventManager.OnStartSpeech += StartSpeech;
        EventManager.OnStopSpeech += StopSpeech;
    }
    
    private void OnDisable ()
    {
        EventManager.OnStopSpeech -= StopSpeech;
        EventManager.OnStartSpeech -= StartSpeech;
    }
    
    private void StartSpeech (AC.Char speakingCharacter, string speechText, int lineID)
    {
        if (speakingCharacter && speakingCharacter.gameObject == gameObject)
        {
            // Character begins talking
        }
    }
    
    private void StopSpeech (AC.Char speakingCharacter)
    {
        if (speakingCharacter && speakingCharacter.gameObject == gameObject)
        {
            // Character stops talking
        }
    }
    
  • thanks a lot, Chris. I'll try this. thanks again and have a nice day

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.