Approach for handling variable enemy vision rather than just on/off

OJDee

New member
Hi all,

I have a sight conditional that, while raycast hits player, increments a sightPercent variable and returns TaskStatus.Running.
When sightPercent reaches 1, it TaskStatus.Success Is returned and enemy can now 'see' player and act accordingly.

While raycast hit is maintained and sightPercent increases, an event is fired passing some variables, which a UI component uses to draw the familiar 'how much has the enemy seen me' display.

This all works fine, however it currently resets the sightPercent to zero whenever the enemy loses raycast hit.

I would like that the sightPercent of an enemy slowly returns to zero over time while raycast does not hit, letting an enemy that nearly 'saw' player to more quickly 'see' player if raycast hit is reacquired soon after losing it. The longer the player stays out of sight, the longer it will take enemy to 'see' player when next in the open.

Since the sight conditional returns TaskStatus.Failure when no raycast hit, it is no longer able to decrease the sightPercent over time.

I was thinking something like having the sightPercent as a shared value and allow it to be increased by this script as raycast hit is maintained but also another that can decrease it. I can't visualise how this would work, however, in conjunction with other tasks.

Perhaps a 'cannot see player' task that just handles this value?


How would you handle such a scenario?

Cheers
Oli
 
For something like this it either makes sense to use a coroutine or have the sightPercent be updated within another script. Within Behavior Designer there isn't a callback that gets run when the task is not active so it will need to be managed somewhere outside of the behavior tree.
 
So I tried using this:
1668069907007.png

The Lose Sight task just decrements sightPercent to 0 and returns success - this works exactly as required in game, however this is a very simple tree so perhaps there is an issue doing it this way as tree gets more complex?

Regarding your suggestion of handling sightPercent external to tree, would this be to use SendEvent task when Raycast hits and have sightPercent increased externally in a class that monitors event, then SendEvent back to tree when sightPercent is 1. When tree ReceivesEvent it acts accordingly?

Thanks
 
The Lose Sight task just decrements sightPercent to 0 and returns success - this works exactly as required in game, however this is a very simple tree so perhaps there is an issue doing it this way as tree gets more complex?
If that works then right now you should go with it. When you build up your tree you can then decide if that's the best route.


Regarding your suggestion of handling sightPercent external to tree, would this be to use SendEvent task when Raycast hits and have sightPercent increased externally in a class that monitors event, then SendEvent back to tree when sightPercent is 1. When tree ReceivesEvent it acts accordingly?
That's one option, or you could set a shared variable value and then have the tree watch that value: https://opsive.com/support/documentation/behavior-designer/variables/
 
Top