Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by sanderbos24 · Mar 22, 2017 at 04:47 AM · c#raycastvrcontrollergoogle

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 (https://www.youtube.com/watch?v=gllyvcrB69I) 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;    
         }
 
     }
 }
 
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image dsternfeld · Mar 23, 2017 at 12:21 AM 0
Share

What is "otherGameObject"? Is that a reference to GvrControllerPointer?

avatar image sanderbos24 dsternfeld · Mar 23, 2017 at 02:57 AM 0
Share

that is the object i'm trying to 'pickup'

The thing is i can't figure out WHERE and HOW I can shoot a raycast from the daydream controller. With Cardboard e.g. you just 'shoot' a raycast from the middle of the screen through your camera, but in Daydream i need to shoot a raycast from the controller, not the camera but i can't figure out which classes i have to reference....

Is the raycast being made in 'GvrLaserPointer' or in GvrLaserPointerImpl? in 'GvrController' maybe? The documentation doesn't help...

avatar image dsternfeld sanderbos24 · Mar 24, 2017 at 06:35 PM 0
Share

I know you've already discovered this, but to help future people:

The plugin integrates with Unity's Event System for raycasting. https://docs.unity3d.com/$$anonymous$$anual/EventSystem.html

This includes custom Input $$anonymous$$odules and Custom Raycasters. GvrPointerInput$$anonymous$$odule GvrPointerGraphicRaycaster GvrPointerPhysicsRaycaster

The raycasting is done by the raycasters, and you can respond to events via EventTrigger of IEventSystemHandlers. https://docs.unity3d.com/$$anonymous$$anual/SupportedEvents.html

$$anonymous$$ore detail can be found at https://developers.google.com/vr/unity/guide under the section "User Interaction".

If you have a use case where you want to do your own raycasting you can access the transform that the raycast should originate from like this: GvrPointer$$anonymous$$anager.Pointer.PointerTransform. If you are using the GvrControllerPointer prefab, the PointerTransform refers to the laser. If you are using GvrReticlePointer, the PointerTransform refers to the reticle.

An example of how this is setup can be found in the scene GvrDemo within the plugin.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by fiixed · Mar 23, 2017 at 03:14 AM

Hey @sanderbos24,

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

http://www.sdkboy.com/2016/12/building-daydream-controller-based-app-scratch/

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

http://www.sdkboy.com/2017/03/daydream-vr-raycast-data-gvrbasepointer-without-eventtrigger/

Hope this helps.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sanderbos24 · Mar 23, 2017 at 03:40 AM 0
Share

oh thanks a lot! The first one i did indeed, but it's a 'closed' system, don't know what's going on in the 'EventTrigger' of the object. The second one i didn't see yet! If i understand correctly you attach this script to the 'player', but you still need an GvrEventSystem right?

avatar image fiixed sanderbos24 · Mar 23, 2017 at 03:44 AM 0
Share

Yes, you attach the script to the player.

You need a GVREventSystem in the Hierarchy (from the prefab in the SD$$anonymous$$), but thats it.

avatar image dsternfeld sanderbos24 · Mar 23, 2017 at 04:41 PM 0
Share

You can all implement EventSystemHandlers ins$$anonymous$$d of using Event Trigger. https://docs.unity3d.com/ScriptReference/EventSystems.IPointerClickHandler.html

avatar image
0

Answer by sanderbos24 · Mar 23, 2017 at 04:27 AM

Now I got the teleportation to work i'm trying to pick stuff up. I'm copying this tutorial (https://www.youtube.com/watch?v=runW-mf1UH0) (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.. :P

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image dsternfeld · Mar 23, 2017 at 04:45 PM 0
Share

Ins$$anonymous$$d of using the camera as the mainController, you probably want the pickupable object to follow the daydream controller. Try using GvrPointer$$anonymous$$anager.Pointer.PointerTransform to access it.

GvrPointer$$anonymous$$anager.Pointer.PointerTransform is the transform used to create the raycast when you use GvrEventSystem and GvrPointerPhysicsRaycaster. If you use GvrControllerPointer for daydream, then the pointer is the laser. If you use GvrReticlePointer for cardboard, then the pointer is the gaze based reticle at the center of the screen. The scene GvrDemo should show how this is all setup.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

351 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Camera Follow Script destroys Raycast on VR-Hands with Late Update 1 Answer

I want to be able to create a script that when I look at an object the player moves to the location of that object. 0 Answers

[Daydream][C#]How would I make a simple directional controller with Google Daydream Controller? 1 Answer

GoogleVR / C# - How to, with the "pointer click": click 1 move a cube and click 2 move back the cube 0 Answers

Get Direction From Raycast 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges