private void Update()
{
if (Input.touchCount > 0)
{
touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Moved)
{
Vector3 touchedPos = Camera.main.ScreenToWorldPoint(new Vector3(touch.position.x, 0, 0));
transform.position = Vector3.Lerp(transform.position, touchedPos, lerpMultiplier * Time.deltaTime);
}
}
}``` I was working on this for 3-4 hours, my brain want to explode already, I'm kinda new to touch. So, the problem Im having is that I want to move a gameobject only on one axis and not x and y with my finger but all will move at the same time. There should be a tag to handle touch
#Raycast to drag an item
1 messages · Page 1 of 1 (latest)
1 way is to use Dot product.
- Cache the position when you press the screen.
- Get the direction from cache towards the now-pressed point.
- Calculate dot product of this vector and something like Vector3.Right
- If the abs value is higher than a threshold, then only move on x axis. Else, only move on y axis.
Is that what you meant?
hmmm... idk much about dotproduct