Forum rules - please read before posting.

How to do a NPC looks-away puzzle?

I'm trying to do a NPC looks-away puzzle, where the player is only able to take an item when the NPC is not looking. So I'd like to automatically be alternating between two NPC animations, an idle animation where you can enter a conversation but not take the item, and a second animation where the NPC turns away thus allowing the player to take the item. How is something like this set up?

Comments

  • I would link an AC variable (either global or component) to an animation parameter in your character's animator -- AC has a script that does just that (it's called "Link Variable to Animator"). A one-way link (variable -> parameter) is how I'd do it. Use that parameter as a condition to transition back and forth between your Idle animation and the LookingAway one. Then you can use the same AC variable as a condition when you interact with the item's hotspot.

  • I found the script, but how do I attach it?

  • Drag it onto the object's Inspector, or click "Add Component" and type in its name.

    A puzzle very similar to this can be found in the "Puzzle template: Simple examples" package over on the Downloads page.

    The "Simple Timer" scene features a key that must be taken while an NPC is sleeping, which is visualised with animation.

  • edited May 2023

    Sorry, I'm having a hard time understanding how this script works, as the only variables I've used so far, are Local and Global variables in my actionlists.
    Now I've attached the 'Link Variable to Animator' script to the NPC's GameObject that holds the animation controller, is this correct, because I can't find a way to attach it directly to the animator itself?
    In the Animator tab I can create parameters that is either Float, Int, Bool, Trigger. But I don't know what to do once one is created, there are no options for them and I can't seem to use them anywhere? In the scripts 'variable location' I can choose 'world' which gives me no options, and 'component' which gives me a selection box but there is nothing to select inside.

    https://imgbox.com/A9gNrtya

    https://imgbox.com/lKECcM5k

  • edited May 2023

    If you want to use a global variable, simply enter the name you gave to the variable into the "Shared Variable name" field. Your animator parameter should have the same name. That will be enough to link them.

    Or, if you want to use a component variable, you can add a "Remember Variables" component to BurgerSeller_Char. This will automatically add a "Variables" component to it too. Create a bool called, for example, 'Distracted?', and enter the name into the "Shared Variable name" field. Don't forget to call your animator parameter 'Distracted?' too, and you should be good to go.

    You asked if you need to attach those components to the NPC's GameObject -- you can do that, but you don't have to. As long as the "Variables:" and "Animator:" fields are assigned in the 'Link Variable to Animator' script , the components can be anywhere in the scene.

  • @Rairun much appriciate your help, I've set it up like this:

    https://imgbox.com/o7Onq4v4

    https://imgbox.com/VyaA5CjN

    That all works now, I can have him change from Idle to Turn away animation by setting the 'Distract?' variable to true in an actionlist. But I'm not sure how to achieve what I wanted in the first place.
    I want the BurgerSeller on scene start to be playing his idle for 5 seconds then switches to Turn away animation for 3 seconds, then back to idle and the 2 animations keep looping like that. When the idle animation is playing, the player can interact with his hotspot for a conversation, but is not allowed to take the mayonaise item. When the Turn away animation is played, the player can no longer interact with his hotspot for conversation, but is now able to take the mayonaise item. So where do I go from here to achieve this?

  • You can make use of a timer set to run on a loop (this action can be found under the "Variables" category), or even just loop a background actionlist yourself (by connecting the last node to the first one). You can use this to toggle the "Distracted?" variable between 5 second waits.

    If you just want to turn the hotspot on and off, you can do that at the same time you toggle the variable. But you could also just leave the hotspot always on, but give different results when the player interacts with it -- just include a variable check at the beginning of the hotspot actionlist, branching into different results (i.e. Speech: "I can't do that, he'd see me!" vs taking the item).

  • @Rairun If the burgerseller has a looping actionlist running in the background, how do I prevent the loop from running when the player starts a conversation with him? Otherwise he will keep turning his back to the player while talking.
    Is there a way to pause the actionlist running in the background?

  • The ActionList: Pause or resume Action can be used to temporarily stop an ActionList from running midway-through.

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.