Answer the question
In order to leave comments, you need to log in
How to make movement constraint on x,y,z?
Hello, I can not do the restriction of movement in any way. (like invisible borders)
The movement is implemented through touching the screen (Android)
The script itself is attached to the camera, the game is in 3D.
public Transform target;
private Vector3 offset;
private float distance;
void Update()
{
if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
offset = target.position - hit.point;
distance = hit.distance;
}
}
if (Input.GetMouseButton(0) && !Input.GetMouseButtonDown(0) && target != null)
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
Vector3 v = ray.direction;
target.position = ray.origin + v * distance + offset;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question