I am trying to make it so when the player presses the b/y button on the VR controller a ball spawns in their hand and then they have the ability to throw the ball by releasing the button. But as of now the ball falls to the ground but is still influenced by the hand parent. here is what I have now.
` // 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?
,
↧