Pick up Objects using Google Daydream Controller

Hi Everyone,

I’m stuck with the Google Daydream Controller. I want to pick up an object when I press the AppButton. I tried several tutorials (Unity VR: Drag and Drop w/ Gaze Input (Cardboard, GoogleVR) - YouTube) but it doesn’t work. I can’t find a tut for Daydream.
Although i look at the Gvr references, i get confused what classes and functions to use to make it work.

I can get the rotation the same as the controller and i thought parenting the object to the Daydream controller would work, but it’s not…

Can somebody explain how to pick something up using the Daydream Controller?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ClickChangeColor : MonoBehaviour {



	GameObject otherGameObject;

	//Vector3 v = GvrController.Orientation * Vector3.forward;

	// Use this for initialization
	void Start () {
				otherGameObject = GameObject.FindWithTag ("Pickup");
		}
	
	// Update is called once per frame
	void Update () {
				if (GvrController.AppButton) {
			gameObject.transform.localRotation = GvrController.Orientation;
			//gameObject.transform.SetParent(Transform );
			gameObject.transform.parent = otherGameObject.transform;    
		}

	}
}

Hey @sanderbos24,

I found this tutorial really helpful. Its written by a Google dev and he uses raycasts from the controller for teleportation.

In this shorter one, he shows how to get the raycast without using an event on the target:

Hope this helps.

Now I got the teleportation to work i’m trying to pick stuff up.
I’m copying this tutorial (Unity3D Tutorial - Pickup and Carry Objects - YouTube) (min. 7:45) and replace it with the Daydream components.
It seems to have problems with the ‘IsKinematic’ function in void carry.

i attached this script to the ‘player’ and the ‘Pickupable’ script to an object i want to pick up.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PickupObject : MonoBehaviour {
	GameObject mainController;
	bool carrying;
	GameObject carriedObject;
	public float distance;

	// Use this for initialization
	void Start () {
		mainController = GameObject.FindWithTag ("MainCamera");
	}

	// Update is called once per frame
	void Update () {
		if (carrying) {
			carry (carriedObject);
		} else {
			pickup ();
		}
	}
	void carry(GameObject o) {
		o.rigidbody.IsKinematic = true;
		o.transform.position = mainController.transform.position + mainController.transform.forward * distance;
	}

	void pickup ()
	{
		if (GvrController.AppButton) { 
			GvrLaserPointerImpl laserPointerImpl = (GvrLaserPointerImpl)GvrPointerManager.Pointer;

			if (laserPointerImpl.IsPointerIntersecting) {
				Pickupable p = GetComponent<Pickupable> ();

				if (p != null) {
					carrying = true;
					carriedObject = p.gameObject;							

				}
			}
		}
	}
}

‘Pickupable script’ (nothing) in it yet)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Pickupable : MonoBehaviour {

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		
	}
}

I feel like i’m almost there, but i’m missing something… :stuck_out_tongue: