News › Forums › RAIN › General Discussion and Troubleshooting › Custom action
Tagged: Custom Action, Expression
This topic contains 7 replies, has 2 voices, and was last updated by Sigil 2 months ago.
-
AuthorPosts
-
September 20, 2022 at 7:36 pm #39171
Do you have to create a class file for every custom action? And in the custom action class, since it’s overriding, you can skip the Start and the end part, even when using the ai argument right?
Also why doesn’t rain set memory variable from behavior tree ? why do I need custom action for that too?
Thanks- This topic was modified 2 months, 1 week ago by Stream.
September 21, 2022 at 2:21 pm #39173Every CustomAction needs to be a separate class, although they can inherit and build on each other. If you define public variables of the type Expression it will include those in the editor for you. Look around the forums a bit for examples of that (you can use google to do a quick search of the forums).
As for them being separate files, that is a Unity thing, I don’t think RAIN will care, not sure if that is what you were asking though.
You can delete Start and Stop if you don’t need them, although Start is good for setting everything up so that your Execute is fresh.
You can use an Expression node to set any variable in memory, like (myNewVariable = “Blah”).
September 22, 2022 at 3:37 am #39178Bug in the asset? put a constraint, and evaluate expression as the last child element (mine was bool type if that matters), it does NOT set the memory variable, but it works if the evaluate expression is the first
- This reply was modified 2 months, 1 week ago by Stream.
September 22, 2022 at 3:59 pm #39187You’d have to show me the tree, maybe a screenshot. Or you can write it out in pseudocode (using the pre/code tags) like this:
root sequencer expression (expression: myTarget = navigationtarget("Navigation Target"), return: success) move (move target: myTarget)
The expression will only work if it gets reached, you mention that it at the end of something, if any of the previous children failed it wouldn’t get executed as well.
September 22, 2022 at 7:34 pm #39191I understand what you mean, but that’s not the case.
Behavior Tree Code
root parallel<-- putting sequencer also doesn't matter, tried both detect (visual sensor - eyesight) [form Variable = formVar] constraint (formVar != null) Move (mountVariable) expression (PlayerInSight = true) Here, it doesn't set it to true, if but does set it if it's put before move
But
September 22, 2022 at 9:58 pm #39197OK, well very likely what is happening is that your AI is working on moving towards the player. The move node will hold on to execution until it gets within close enough distance of its target.
Try it out in the behavior tree debugger and you should see what is happening. Select your AI and change the drop down in the behavior tree to the Current AI (top option I think). When you press play it should light up with colors representing what is going on. What you will probably see in the first image is that the move node is yellow, and the expression isn’t lit yet.
A few notes on your tree:
When you have multiple items in a constraint it behaves like a sequencer. So it will wait until the first item returns success before moving on to the next. In your case it is waiting for the move node to finish before evaluating the expression.
Your expression node is currently set to return the evaluated result, and since it is an assignment (PlayerInSight = true) it is returning whatever PlayerInSight equals when you’re done (obviously true in this case). While it works this time, it may not be what you intended, for instance if you were to do PlayerSpeed = 0 instead, it would have returned 0, which ends up being treated as a failure. Generally when you are doing an assignment you probably want to set it to return success or failure explicitly.
Let me know if my first observation is off, otherwise come back if you have more questions.
September 25, 2022 at 9:30 pm #39212Could you please answer these questions about sensors
1. The Visual Sensor, it looks like it’s doing distance or range check + Vector angle calculation, and not a raycast? because it also detects the Target even when it’s behind a wall. Normally, how do you make it a realistic visual Line of Sight in that case? (The outdated? doc mentions it, but I couldn’t find it among Visual Sensor setting)
2. The Audio Sensor, does it get triggered if the Aspect comes within the Range and plays any sound, or is it just like a Visual Sensor that it detects Aspect regardless of whether the Aspect is playing any sound or not?
Now let’s say the Aspect is within the Audio Sensor range, but the Audio clip’s range is NOT actually reaching the AI for eg:
I mean, the Audio sensor range say is set to 30, the Aspect is just in that range (eg. 25 units away), but the Audio Clip is supposed to be heard say at the distance of 5 only.
Will the AI still detect it? (I have no actually worked with sound so I am not sure and asking you)Thanks
- This reply was modified 2 months ago by Stream.
September 29, 2022 at 10:11 am #392231) Select “Show Advanced Settings” from the component menu (gear icon, upper right of AI Rig component). Line of sight should show up after that.
2) The audio sensor will only check audio aspects that fall within its range. For any audio aspect within the range it will check if the audio clip is playing, if the sensor is within the max distance of the audio clip, and if the volume of the audio clip is over the volume threshold (given the range and falloff of the audio clip).
So using your example: If the audio clip can only be heard 5 meters away, the audio sensor will only detect it when it is 5 meters or closer, even if the range is set to 30. The range on the audio sensor is just to keep us from having to flip through all the audio aspects in the scene… in a future version we may remove it and rely solely on the audio aspects and the associated audio clips volume range.
-
AuthorPosts
You must be logged in to reply to this topic.