Question by
darksawyer95 · Mar 08, 2020 at 12:36 AM ·
touch controlstouchscreen
[Android] Drag object only in XY plane
I'm trying to move an object in AR only around x and y, for doing this I use
var screenPoint = camera.WorldToScreenPoint(transform.position);
// Add the deltaPosition
screenPoint += (Vector3)screenDelta;
// Convert back to world space
newposition = camera.ScreenToWorldPoint(screenPoint);
transform.position = newposition;
Where screen delta is the difference vector from where the finger start dragging to the end of it. What I have already tried is to save the transform.z information before the camera.ScreenToWorldPoint is invoked and then apply it to the final result. It works only if the I look at the world with the X axes in front of me, but when I move around I'm able to move the object only up and down... How could I solve this??
Thank you in advance
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612224540im_/https://answers.unity.com/themes/thub/images/avi.jpg)