Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice
  2. Read here for Unity's latest plans on OpenXR.
    Dismiss Notice

ARCore - Lean touch - Move object in X and Z axis (I want to Lock Y axis)

Discussion in 'AR/VR (XR) Discussion' started by sweetan, Apr 26, 2018.

  1. sweetan

    sweetan

    Joined:
    Nov 21, 2017
    Posts:
    17
    Hi,
    I have created object moving app using ARCore. for object move purpose I have used Lean touch it works fine, But I want to lock axis Y it's overlapping my ground plan.
    Please help to solve this issue.
    Thanks in advance.
    Sweetan M
     
  2. Atulyextel2

    Atulyextel2

    Joined:
    Jan 10, 2018
    Posts:
    11
    If you r using lean touch translate script then its really easy to clamp the y movement, just open the script and swap the y and z components. I have done it and if u need the edited script the just ping me .
     
  3. robrtoprz

    robrtoprz

    Joined:
    May 15, 2017
    Posts:
    9
    Hi @Atulyextel2
    Can you please show us how did you do that? I'm a beginner and I would like to see how did you do that change.

    Thank you.
     
  4. rocketpadmedia

    rocketpadmedia

    Joined:
    Jun 19, 2017
    Posts:
    1
    Hey @Atulyextel2 - I'm looking to figure this out as well. Would love to see the edits you have for the script! Thanks.
     
  5. Atulyextel2

    Atulyextel2

    Joined:
    Jan 10, 2018
    Posts:
    11
    Hi,
    sorry, bro replying late. first, u have to use the latest version of lean touch.
    just change the LeanTranslateSmooth.cs script of lean touch with below code and the use LeanTranslateSmooth.cs script to translate. all the code is same as LeanTranslateSmooth script but I have just done few adjustments, I have commented my changes. best of luck and let me know if this works for u...
    Code (CSharp):
    1. using UnityEngine;
    2. namespace Lean.Touch
    3. {
    4.     // This script allows you to transform the current GameObject with smoothing
    5.     public class LeanTranslateSmooth : LeanTranslate
    6.     {
    7.         [Tooltip("How smoothly this object moves to its target position")]
    8.         public float Dampening = 10.0f;
    9.         // The position we still need to add
    10.         [HideInInspector]
    11.         public Vector3 RemainingDelta;
    12.         protected virtual void LateUpdate()
    13.         {
    14.             // Get t value
    15.             var factor = LeanTouch.GetDampenFactor(Dampening, Time.deltaTime);
    16.             // Dampen remainingDelta
    17.             var newDelta = Vector3.Lerp(RemainingDelta, Vector3.zero, factor);
    18.             // Shift this transform by the change in delta(Atul`s change)
    19.             Vector3 moveMe = (RemainingDelta - newDelta);
    20.             moveMe.z = moveMe.y;
    21.             moveMe.y = 0f;
    22.             Debug.Log("move me : " + moveMe);
    23.             //transform.position += (RemainingDelta - newDelta);
    24.             transform.position += moveMe;
    25.            // Debug.Log("pos : "+transform.position);
    26.             // Update remainingDelta with the dampened value
    27.             RemainingDelta = newDelta;
    28.         }
    29.         protected override void Translate(Vector2 screenDelta)
    30.         {
    31.             Debug.Log("HI!!!!SSSS");
    32.             // Make sure the camera exists
    33.             var camera = LeanTouch.GetCamera(Camera, gameObject);
    34.             if (camera != null)
    35.             {
    36.                 // Store old position
    37.                 var oldPosition = transform.position;
    38.                 // Screen position of the transform
    39.                 var screenPosition = camera.WorldToScreenPoint(oldPosition);
    40.                 // Add the deltaPosition
    41.                 screenPosition += (Vector3)screenDelta;
    42.                 // Convert back to world space
    43.                 var newPosition = camera.ScreenToWorldPoint(screenPosition);
    44.                 // Add to delta
    45.                 RemainingDelta += newPosition - oldPosition;
    46.             }
    47.         }
    48.     }
    49. }
     
  6. robrtoprz

    robrtoprz

    Joined:
    May 15, 2017
    Posts:
    9
  7. isasaurio

    isasaurio

    Joined:
    Nov 13, 2016
    Posts:
    14
    @Atulyextel2 and for limit te rotation only in Y axis?
    Can you help me?
    Thanks!!!
     
    unity_XY9GfkpHMyaikw likes this.
  8. alevy97

    alevy97

    Joined:
    Sep 3, 2018
    Posts:
    2
  9. felixhdyw

    felixhdyw

    Joined:
    Jun 12, 2018
    Posts:
    2
    @Atulyextel2
    Thank You!! I am using ARCore as well, is it possible to clamp the movement according to the "detected plane"? since ARCore needs to detect the plane first in order to generate usable plane[/QUOTE]
     
  10. F_A_Duque7

    F_A_Duque7

    Joined:
    Sep 23, 2018
    Posts:
    1
    Works well,but.... only if you don´t move. If you move to your left and then you try to move the object the system of coordinates becomes crazy. I guess it only works if you are in the same position/ orientation of the world system of coordinates. Do you know how to fix it? because I am really tried of trying.
    Thanks
     
  11. Kerber996

    Kerber996

    Joined:
    Nov 9, 2016
    Posts:
    23
    If anyone is having trouble using this in a case @F_A_Duque7 mentioned, just comment the 20th line (moveMe.z = moveMe.y;) :D
     
    TomKhan3 and AlbyDj90 like this.
  12. TomKhan3

    TomKhan3

    Joined:
    Jul 21, 2017
    Posts:
    18
    @Kerber996 Thank you! Saved me hours of hunting!
     
  13. michicata25022015

    michicata25022015

    Joined:
    Feb 8, 2021
    Posts:
    1
    helou, my name is Alison someone knows how to lock the z axis in unity with augmented reality
     
unityunity