Hello
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?
ps:
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
Toryn