Spawn object in hand and bind it to hand transform?
Hi there, I am trying to implement a simple VR darts throwing game. I want it to work so that pressing the trigger on the Oculus touch makes a new dart spawn in the user's hand and bind it to the hand's object attachment point orientation and position. I have created a new action binding in the SteamVR interaction system to spawn a dart in the hand, and it works.
The problem is that I want to use the trigger to both spawn the dart (by instantiating the relevant game object) and "grab it" thanks to the built in interactable script at the same time. The dart having a rigidbody using gravity attached to it, tends to fall off when I try to grab it, and it will only attach to my hand if the controller is in a particular orientation. Can anyone think of a simple way to make sure that the dart spawns and stays attached to my hand properly until I throw it? Thanks in advance!
Answer by KittyAnn · Apr 12, 2019 at 06:28 PM
@el16al I have a 3d RPG game I'm making. My player picks a "magical flower" & it becomes a sword in her hand. To accomplish this I have made TWO identical characters BUT on the 2nd one I have added the sword. So when the player collides with the "fake sword" (or clicks on it to pick it up in your case), the 1st player is "SetActive = false;" and the 2nd player is "SetActive = true;". I do this on another quest in my game if the player is holding the "flower sword" and has to trade it to the NPC for a "butterfly net". I have 2 of both, 2 flower swords (1 named "fake sword" & 1 named "real sword") and set active according to what the needs are. You can swap out "right hand" on your first person (guessing here as I know nothing about VR) NOT holding a dart, and swap in a new "right hand holding dart"? I hope this helps!
Answer by DrDigg0R · Apr 20, 2020 at 08:57 PM
@el16al I had the same problem and used 'SteamVR_Action_Single' (which gives you a float), instead of 'SteamVR_Action_Boolean' to resolve it.
You need a handler like this one: OnSpawnActionChanged(SteamVR_Action_Single fromaction, SteamVR_Input_Sources fromsource, float newaxis, float newdelta)
...and e.g. check if (!alreadySpawned && newaxis > 0 && newdelta > 0f)
Then, the important part is to make sure there is the SteamVR "Throwable" Component on your GameObject which you want to spawn & throw; there you need to set the property "Catching Speed Threshold" to e.g. 0. This way, the object will be attached as soon as it was spawned.
Hope this helps in a way.
Your answer
Follow this Question
Related Questions
Steam VR one object interaction using both controllers 0 Answers
SteamVR 2.0 how to implement distance grab? 2 Answers
SteamVR 2.2 How to set custom input bindings without having a headset connected? 0 Answers
How to disable Vive Controllers 5.5 support 1 Answer
(XR Input) Why does Oculus Rift work fine, but HTC Vive inputs stays at 0 ? 0 Answers