Reputation: 21
I'm able to place a object on a plane using the point cloud but now I'm trying to figure out how to move the object on the same plane when I drag my finger on the screen. Has anyone done this in Unity?
Calling pointCloud.FindPlane on every finger movement to find the plane under the finger is not really efficient. Can anyone suggest a better way?
Upvotes: 0
Views: 179
Reputation: 11
You can track your finger movement and transfer that to the object's localposition.
Something like this:
private bool firstClick = false;
private Vector3 oldMousePosition;
private Vector3 newMousePosition;
void Update ()
{
if (Input.GetMouseButtonDown(0))
{
if (!firstClick)
{
firstClick = true;
oldMousePosition = Input.mousePosition();
}
else
{
newMousePosition = Input.mousePosition();
Vector3 offset = oldMousePosition - newMousePosition;
oldMousePosition = newMousePosition();
transform.localPosition += offset;
}
}
if (Input.GetMouseButtonUp(0))
firstClick = false;
}
Upvotes: 0
Reputation: 180
What I did was call the findplane method at the point where the object is dropped. I did that in Unity and dragging was kind of picking it up, so that made sense for my use case.
Upvotes: 0
Reputation: 1815
I advise you to take a look at ExperimentalFloorFinding
It is an example Scene
located in the Unity
Project folder. I believe it is exactly what you want to achieve. Just double click demo scene in Unity
. Hope that helps you.
Upvotes: 1