Mobile: Touchscript rescales all object even though I only drag/scale one object?
HI. Is anyone familiar with a combination of Vuforia AR SDK and the Lean touch scripts? I am creating a project in which I have multiple child objects of my image target. (a cube, a sphere etc.) When I try to add the transform functionality from the lean touch script it transforms all objects even though I only pick (and touch) one of them.
For those not familiar with the Lean touch script: I have attached a touch script to an empty gameobject. Also each object that needs to be dragged has a draggable and transform script attached. BUT when I touch and scale one object it affects all the other objects aswell. What To Do?
I have attached a image of the hierarchy and the inspector of one of the draggable objects
The transform script: using UnityEngine;
namespace Lean.Touch
{
// This script allows you to transform the current GameObject
public class LeanTransform : MonoBehaviour
{
public bool AllowTranslate = true;
public bool AllowRotate = true;
public bool AllowScale = true;
protected virtual void Update()
{
if (AllowTranslate == true)
{
Translate(LeanTouch.DragDelta);
}
if (AllowRotate == true)
{
Rotate(LeanTouch.TwistDegrees);
}
if (AllowScale == true)
{
Scale(LeanTouch.PinchScale);
}
}
private void Translate(Vector2 screenPositionDelta)
{
// Screen position of the transform
var screenPosition = Camera.main.WorldToScreenPoint(transform.position);
// Add the deltaPosition
screenPosition += (Vector3)screenPositionDelta;
// Convert back to world space
transform.position = Camera.main.ScreenToWorldPoint(screenPosition);
}
private void Rotate(float angleDelta)
{
transform.rotation *= Quaternion.Euler(0.0f, 0.0f, angleDelta);
}
private void Scale(float scale)
{
// Make sure the scale is valid
if (scale > 0.0f)
{
// Grow the local scale by scale
transform.localScale *= scale;
}
}
}
}
Answer by wilbertllama · Apr 25, 2017 at 08:01 PM
Hello, I'm also interested in how to scale objects separately. I searched for solutions too, but the results were not optimal. However, I would like to share them. Maybe it works for you.
option 1
Someone made a video on how he did it. (link: https://drive.google.com/file/d/0B6WOE1SuIGL3VmdfZ0EyVS05WlE/view)
He used an old version of LeanTouch. This can be found here: https://www.ourtechart.com/augmented-reality/tutorial/augmented-reality-touchscreen-events/ (Just download the whole project and copy the Lean Touch map to your project.)
It works on my Android phone for a few minutes, but after 5 minutes or less, the Scaling/Moving stops working properly.
option 2
I also found a youtube video about moving and scaling objects separately. (link: https://www.youtube.com/watch?v=KoPI1-V07aw)
With this tutorial I can move objects separately, but Scaling still does not work for me. (I followed the exact same steps of the tutorial.)
I am still figuring out how to scale the objects separately, and unfortunately, the two methods above did not work for me.
If someone already discovered how to Scale the objects individually (with or without LeanTouch), please share your solution/scripts.
Your answer

Follow this Question
Related Questions
How can I detect a touch on a custom button and object in Unity3d 1 Answer
Trying to drag GameObject using touch input 0 Answers
TouchInput in Update. Physics in FixedUpdate. Lag and Lost calls? 1 Answer
How could I implement diagonal movement in this code? 0 Answers
i want to move object only when i swipe on screen not when touch, Unity 2d Android 0 Answers