Forum rules - please read before posting.

Character walk path setup question

edited November 2021 in Technical Q&A

Hi,

In a scene I'd like to make my NPC character move back and forth AND face the player character immediately, stop for 3 seconds, then continue back to path loops. And I'm having difficulty setting this up correctly. Can anyone help please :)

This is what I do now:
1) I have a straight path setup with 0 and 1 node, the wait time is set to 0 and the path type is set to "loop".
2) I setup an OnStart ActionList in AC Game Editor for this scene with "Character: Move along path" node so my NPC starts moving when the player enters the scene.
3) Within the Path inspector, I setup ActionLists called Path_OnReachNode_0 and Path_OnReachNode_1 for both nodes.
4) Path_OnReachNode_0 and Path_OnReachNode_1 both has "Character: Face direction down" node so they face my player when they reached a node.

My question:
1) Are there anyway to make my NPC starts moving by themself without using OnStart ActionList? I want to reserve my OnStart ActionList for other cutscenes.

I can't find a way to make an ActionList attach to a character.

2) With my current method my NPC character will move to node 0 and 1 on the path. Face the player, then immediately move to the next node. They won't wait after they turn to face the player.

If I change my path wait time to 3, my NPC character will move to a node, wait for 3 seconds facing left or right, then turn to my character, then move again. But I want my NPC to turn immediately then wait for 3 seconds.

Are there any good way to make my characters wait 3 seconds after they face direction down?

Thank you.

Comments

  • Are there anyway to make my NPC starts moving by themself without using OnStart ActionList? I want to reserve my OnStart ActionList for other cutscenes.

    You can use the ActionList Starter component to trigger an ActionList when the scene begins without having to assign it as an "OnStart" cutscene.

    You can attach a Cutscene component to your NPC, and then the above ActionList Starter component. To this component, assign the Cutscene and check Run on scene start?.

    With my current method my NPC character will move to node 0 and 1 on the path. Face the player, then immediately move to the next node. They won't wait after they turn to face the player.

    The NPC will resume moving along the Path once the "node cutscene" has been completed.

    Inserting an Engine: Wait Action of 3 seconds to the end of your Path_OnReachNode cutscene should cause them to wait only after turning.

  • You can use the ActionList Starter component

    Thank you, I'll try that. :)

    Inserting an Engine: Wait Action of 3 seconds

    I've tried Engine: Wait. But it seems that my player character can't move when Engine: Wait is on. But I'd like to keep my player character movable when my NPC looked at my player. :(

  • I've tried Engine: Wait. But it seems that my player character can't move when Engine: Wait is on.

    Set the ActionList's When running field to Run In Background to avoid it blocking gameplay.

    See the Manual's "Background logic" chapter for more on this topic.

  • It works now, thank you. :)

  • Hi, I got another question about handling the NPC.

    This what I'd like to do:
    1) The NPC walk back and forth along a looping path if the players don't interact with it.
    2) If the player uses inventory item "Gun" on the NPC, the player will shoot and kill the NPC. The NPC will play a "death" animation and die right on the spot. The NPC death position and the death sprite remains the same for the rest of the game.

    So far I made a gun interaction hotspot for this NPC, and tried the following action list:

    1) Character Animate, player character plays "shoot" animation.
    2) Character Move along path: Stop Moving, NPC character stops moving on it's path and die on the current location.
    3) Character Animate, NPC character plays death animation.

    This seems to work in the same scene, but if I switch scene by going to another location, then come back to this scene, the NPC came back alive again. It looks like the above action list can't remember my NPC stats.

    I have "Remember NPC" component attached.

    What's the good way to do this?

  • edited November 2021

    Which stats in particular are not being saved? Is the resurrected NPC again moving along the Path, or is it only the animation that's incorrect?

    To save the state of an Animator, a Remember Animator component must also be attached. A Constant ID component should also be present on the Path itself, since the NPC references this.

    Both of these should be added automatically if you use the "Auto-add Save components to GameObjects" button in the Settings Manager.

    What animation engine does the character use, and what are the fields you're using in the "Character: Animate" Action?

  • Is the resurrected NPC again moving along the Path

    Yes, the NPC moves along the path after I change scene.

    a Remember Animator component must also be attached

    I just tried this, but it doesn't work.

    A Constant ID

    My path has Constant ID attached.

    "Auto-add Save components to GameObjects"

    I tried that as well, my NPC still comes back alive :(

    What animation engine does the character use,

    I use default "Sprite Unity".

    what are the fields you're using in the "Character: Animate" Action?

    I use "Play Custom", then the animation file name. Here is the screenshot:

  • How are you moving the NPC along the Path in the first place? In an OnStart cutscene?

    It may be that the NPC's state is being saved, but being overridden by the OnStart logic.

    If the NPC can be killed, you need to make sure that the logic that causes them to move along the Path is not run when this is the case.

    The best way to do this is to attach a Variables component to the NPC, and define a Bool variable named "IsDead". This can be set to True as part of the "player shoots NPC" logic using a "Variable: Set" Action.

    Then, in your scene-start logic, you can use a "Variable: Check" Action to prevent Actions from running if the NPC is dead. The Variables component will need a Remember Variables component to save its value as well.

    If you want to keep your game logic compartmentalised, you can move any NPC startup logic out OnStart and into a separate Cutscene. If you then attach an "ActionList Starter" component, you can opt to have this run when the scene begins as well.

  • Finally found the issue. :)

    Apparently one of my trigger2D is re-activating the NPC movement. I turn it off by teleporting the trigger away after activation and now it's working perfectly. :)

  • Just noticed another problem with the NPC. :(

    I noticed that my character can walk through the NPC. Even though:
    1) Both my player character and NPC has colliders attached.
    2) My player and NPC sprites are on the same sorting layer, on the same order.

    What went wrong? :(

  • edited December 2021

    You'll need to adjust the Character evasion field in your NavMesh's Inspector.

    This is set to Only Stationary Characters by default. The All Characters setting, which allows for evasion when both characters are moving, is more intensive. For this, you'll also need to set a non-zero Pathfinding update time value in your Settings Manager's "Movement settings" panel.

    See the end of the Manual's "Polygon Collider pathfinding" for more details.

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.