Hello there and happy holidays ![]()
I have made a script to move the red object to the right by swiping the screen to the right.
But the camera will orbit the object. So if the camera is on the other side, I’ll have to move the object to the LEFT by still swiping to the RIGHT, because the swipe direction remains the same.
How can I make it move to where the pink arrow points so the direction of the arrow and the direction of the swipe remains the same while the camera orbits around 360 degrees?
This is what I am using:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Move : MonoBehaviour
{
public LayerMask mask;
public float sensitivity;
GameObject selected;
// Update is called once per frame
void Update()
{
OneTouch();
}
void OneTouch(){
if(Input.touchCount == 1){
Touch touch = Input.GetTouch(0);
//ONLY HIT THE RED OBJECT
Ray ray = Camera.main.ScreenPointToRay(touch.position);
RaycastHit hit;
if(Physics.Raycast(ray, out hit, 50f, mask)){
selected = hit.transform.gameObject;
}
//MOVE THE X TO -1.5
if(touch.phase == TouchPhase.Moved){
Vector3 direction = new Vector3(touch.deltaPosition.x, 0, 0);
selected.transform.position += direction * sensitivity / 200;
selected.transform.position = new Vector3(Mathf.Clamp(selected.transform.position.x, -1.5f, 0), 0, 0);
}
}
}
}
I hope I described the problem well.
Thank you ![]()

