Quantcast
Channel: Questions in topic: "parenting"
Viewing all articles
Browse latest Browse all 302

Steam VR, spawn object in hand as grabbed? (Solved!)

$
0
0
Trying to make it so when the player presses either B or Y on the controller a ball will spawn in their respective hand. And when the player releases the ball it will be thrown/ detach. Right now the ball just falls down upon spawning but is still influenced by the hand as a parent. Here is what I have so far: // a reference to the action public SteamVR_Action_Boolean SpawnBallFromPool; // a reference to the hands public SteamVR_Input_Sources handTypeRight; public SteamVR_Input_Sources handTypeLeft; public GameObject handRight; public GameObject handLeft; void Start() { SpawnBallFromPool.AddOnStateDownListener(TriggerDown, handTypeRight); SpawnBallFromPool.AddOnStateUpListener(TriggerUp, handTypeRight); SpawnBallFromPool.AddOnStateDownListener(TriggerDown, handTypeLeft); SpawnBallFromPool.AddOnStateUpListener(TriggerUp, handTypeLeft); } // For releasing the ball to be thrown. public void TriggerUp(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource) { Debug.Log("Trigger is up"); GameObject Ball = ObjectPooler.SharedInstance.GetPooledObject(); Ball.transform.parent = null; } // Summons ball in hand on button press down. public void TriggerDown(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource) { Debug.Log("Trigger is down"); GameObject Ball = ObjectPooler.SharedInstance.GetPooledObject(); if (Ball != null) { Ball.transform.position = handRight.transform.position; Ball.transform.rotation = handRight.transform.rotation; Ball.transform.parent = handRight.transform; Ball.SetActive(true); } } Any tips?

Viewing all articles
Browse latest Browse all 302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>