Picking and leaving items
- Last UpdatedDec 06, 2023
- 2 minute read
Preparing items for pick and leave
To manage picking and leaving actions, prepare items accordingly.
-
Items must be provided with User actions so that they have triggers for picking and leaving.
-
Attach points must be prepared so that the items can be left.
-
Items should be initially linked to some attach point.
Picking items
Picking means being able to assign an item to the manipulator and eventually taking it from an attach point.
To make an item capable of picking
-
Select it Using a selection tool item by colliding with it.
-
Use an action on the item to trigger pick-up.
Pick action
The code triggered by the pick action should do the following things:
-
Assign item to manipulator using start_manipulator.
-
Hide the selection tool.
Example code
Example code for picking configuration.
<route from="aTool.action\take\state" to="cmd_switchHand2Tool.execute" condition="@aTool.action\take\state@==started" value="aTool" />
<Command name="cmd_switchHand2Tool">
<local name="newTool" type="sstring" value="%0%" />
<setfield name="@%newTool%@.action\\take\\active" value="false" condition="[@[@%newTool%].userActions.contains(take)]" />
<setfield name="selection_tool.visible" value="false" />
<execute command="start_manipulator" value="@%newTool%@" />
</Command>
Leaving items
Leaving means being able to remove an item from the manipulator and eventually assigning to an attach point.
To make an item capable of leaving
-
Enter the sphere of an AttachPoint that can host the manipulated item.
-
Use an action on the item to trigger the leaving of the item.
Leave action
The code triggered by the leave action should do the following things:
-
Attach manipulated node to the AttachPoint.
-
Assign selection tool to the manipulator using start_manipulator.
-
Show the selection tool.
Example code
Example code for leaving configuration.
<route from="aTool.action\leave\state" to="cmd_switchTool2Hand.execute" condition="@aTool.action\leave\state@==started" />
<Command name="cmd_switchTool2Hand">
<if condition="@manipulator.nearAttachPoint@!=" >
<local name="oldTool" type="sstring" value="@manipulator.manipulatedNode@" />
<local name="poa" type="sstring" value="@manipulator.nearAttachPoint@" />
<setfield name="@%oldTool%@.action\\take\\active" value="true" condition="[@[@%oldTool%].userActions.contains(take)]"/>
<setfield name="@%oldTool%@.action\\leave\\active" value="false" condition="[@[@%oldTool%].userActions.contains(leave)]"/>
<setfield name="manipulator.attach" />
<setfield name="selection_tool.visible" value="true" />
<execute command="start_manipulator" value="selection_tool" />
<execute command="cmd_inventoryRemItem" value="@%oldTool%@" />
</if>
</Command>
Complications
The code shown on the picking and leaving topics works for most of the cases, but sometimes picking and leaving includes complications that must be managed with dedicated code.
Some examples.
Tester
The collisionable object is the tester instrument. You need to assign its lead sensors to the manipulator when using. The tester itself could be placed in front of main camera to read its values when using its sensor to measure something.
Clothes and dummy
The same item may have different looks when placed inside a locker or when dressed on a dummy. This means being able to manage two different items that pretend to be the same and being able to adapt the ghost to show depending on nearest AttachPoint.