Code that should always run

NodeCanvas Forums General Discussion Code that should always run

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #9046

    Hello!

    I’ve been trying to implement a pretty standard behaviour for an NPC. When he sees the player, a gameobject AttackTargetLastSeen is created, or if existing, moved. So, even when the NPC doesn’t see the player anymore, he will still move to that Last Seen Position Object.

    Now the thing is, I have to keep updating the Last Seen Position while the NPC Moves to the player. I was only able to achieve it with the setup you see below. Basically the code to update the LastSeen Object is in the conditional Node if NPCNew Last Seen. In this custom Node i always return false, so the update code in it keeps running.

    Now my question would be: This seems kind of a hack, a Condition that always returns false. Where would you put Code like that which must run, even when i.e. a Move To Task is executing at the same time?

    I also tried to return true from the NPCNew Last Seen Condition whenever the Last Seen Position changes. But then, while the player moves in front of the NPC and thus always changing the Last Seen Position, that node returns true continually and keeps interrupting the Move To oder. The effect is, that the npc only resumes moving when the player stands still.

    Any pointers would be appreciated 🙂

    #9048
    Gavalakis
    Keymaster

    Hello,

    This is probably the most asked question as far as BT pattern goes 🙂
    So, the way to run parallel actions is of course to use the Parallel node. If you want to run an action while a condition is true this can also be achieved with a Parallel + Repeater or just a Repeater. Depends.

    I’ve attached 3 images:

    1. The Parallel node ticks both childs silumtaneusly on each Tick. Because it is set to First Failure and it is Dynamic, if the condition returns Failure, the rest of the Running children (in this case the Repeater) will be interrupted. But while the condition is true, the Repeater will keep ticking the Action ‘Forever’.

    2. Another solution for a while-do loop is this use of a “Repeater Until Failure” prety much self explanatory 🙂

    3. Just a idea of how you could do a go to last seen position with the available tasks. It might not be exactly what you want, but works fine :). (remember that an Accessor is practicaly the same as a Sequencer with a condition as a first child). The 2nd Accessor does not need to be Dynamic, or else it will immediately be interrupted due to the hadLost becoming false.
    If both of these child nodes return Failure, it either means that the agent can’t go to that position or never had a LOS with the sphere (target). It will even work dynamicaly meaning that the agent will not need to come to a full stop.

    As a final word. If you want to run actions in parallel, the Parallel Composite node is what you need. I just expanded on that on my eplanation so that I provide more insightfull information.

    Let me know if you have any question
    Cheers!

    Join us on Discord: https://discord.gg/97q2Rjh

    #9047

    Hey Gavalakis

    I’ve implemented the variant with the Parallel and Repeater. Works great! Thank you

    #11276
    feelx
    Participant

    Hi,

    just out of curiosity – are old images deleted on this forum or why aren’t there any in these posts?

    #11278
    Gavalakis
    Keymaster

    Hey,

    Some time ago there has been a forum migration. During this migration, all forum images were lost. Other than that, there is not auto-deleting post images based on date, no.

    Join us on Discord: https://discord.gg/97q2Rjh

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.