Reading out variables at realtime - general questions

justinheinen

New member
Hi, iam trying to set a float variable from behavior tree to a one in my script.

Iam comparing that float to 0, if yes the left side should be played which lets the enemy die. Can i compare to <1 ? Or do i have to limit that in code ?

When would you sync this float ? After taking damage ? And how would you do this properly ?

with m_behaviortree.SetValue("Health" , currenthealth ); ? Or is there a better way ? I guess mapping that variable would be a little bit too much because its not nescessary every frame.

1576957231326.png

Second question:

Is this generally a good approach for this ? When should you use tasks for disabling rigidbodies etc. and when should you just invoke a method which does all that ? My enemies need to get a weapon disabled. Will i do this via a task which disables a unity gameobject, or would i call it in the "onDeath" Function which is already getting invoked ?

I guess when doing every single line of code in tasks it gets messy fast. Is there any hint how to start right at this ?


Third question:

how to properly use behavior trees. Would you create one tree for each enemy type ? Would it make sense to separate trees ? Like one tree which does the seeking for player, and one which handles the shooting ? Or would you do this all in one tree ?



Thank you
Justin
 
Last edited:
Iam comparing that float to 0, if yes the left side should be played which lets the enemy die. Can i compare to <1 ? Or do i have to limit that in code ?

When would you sync this float ? After taking damage ? And how would you do this properly ?

with m_behaviortree.SetValue("Health" , currenthealth ); ? Or is there a better way ? I guess mapping that variable would be a little bit too much because its not nescessary every frame.
I would use the Float Comparison task. This allows you to compare two arbitrary values.

Is this generally a good approach for this ? When should you use tasks for disabling rigidbodies etc. and when should you just invoke a method which does all that ? My enemies need to get a weapon disabled. Will i do this via a task which disables a unity gameobject, or would i call it in the "onDeath" Function which is already getting invoked ?

I guess when doing every single line of code in tasks it gets messy fast. Is there any hint how to start right at this ?
I agree that doing one line of code per task gets very verbose. You could instead combine more logic into a single task. As an example the Seek task will keep active for as long as it isn't at the destination, instead of having one task for setting the destination and another task for checking if the agent is at the destination.

how to properly use behavior trees. Would you create one tree for each enemy type ? Would it make sense to separate trees ? Like one tree which does the seeking for player, and one which handles the shooting ? Or would you do this all in one tree ?
I would put both seek and shooting in the same tree. But it largely depends on your thought process and there's no one right answer. For some more ideas take a look at this tree which is a fairly large behavior tree and I think has some of the behavior that you are going for:

 
Top