How to drag objects around with controller?

I am trying to be able to drag gameobjects around the scene with the Nreal computational controller.
I want to be able to place objects where i want them.
I tried to use the handtracking, but it was quite fiddly and unstable to be able to place game objects semi accuratly.

Can anybody help me with this?

I can make it work when i run it inside unity, but that uses mouse inputs not the controller.
At the moment my code looks like this:

namespace NRKernal

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

    //Code for mouse input
    public class DragObject : MonoBehaviour
        //Code for pointer input

        private Vector3 pOffset;

        private float pZCoord;
        private void OnPointerClick()
            pZCoord = Camera.main.WorldToScreenPoint(gameObject.transform.position).z;
            // Store offset = gameobject world pos - mouse world pos
            pOffset = gameObject.transform.position - GetpointerWorldPos();

        private Vector3 GetpointerWorldPos()
            //pixel coordinates (x,y)
            Vector3 pointerPoint = NRInput.GetPosition();

            //z coordinate of game object on screen

            pointerPoint.z = pZCoord;

            return Camera.main.ScreenToWorldPoint(pointerPoint);
        private void OnPointerDrag()
            transform.position = GetpointerWorldPos() + pOffset;

Best regards

I use the following interfaces:


There’s more, but I mostly use those :stuck_out_tongue:

You’ll find a good example code in the Controller page in the NReal developer site.

All of these are already compatible with NReal laser pointers (the ones with NRPointerRaycaster component).

You’ll find whatever laser pointer (either phone or hand) in this:


And in case of hand tracking, you can get which hand has the laser from this:


As a note, an object will also receive interface events from its children. I use this to make sure the events came from the parent:

        if (eventData.pointerEnter != gameObject) // if the event is not coming from this object, we leave

1 Like

Thanks for your reply.
I still could not get it to work, but with the new SDK i got some other problems.

I tried your method of manipulating the GameObjects with the evenData …but it only updates only once and while setting the object’s transform it goes to the origin of the raycast.

I some how want it to move with my raycast …and this should be done in update() if i am not wrong …

Can you provide a bit more clarity and code on how you implemented this functionality.

I really do need this to work