Good day!

There is an area on which the Mask elements are installed. In this area we have an object that must move to the place where the click was made (tap, touch).

enter image description here

enter image description here

I managed to adjust the movement from one object to another. But when using the commented line, the object flies to infinity. Moreover, this method does not provide the necessary coordinates. It removes coordinates only from the visible area of ​​the field on which the object is located.

enter image description here

Using Ray, nothing comes out, the object stops responding altogether.

How can I solve this problem?

PS: Android, not PC. Tachi needed ...

    2 answers 2

    I did not check the code.

    void Update() { if (Input.touchCount > 0) { Touch touch = Input.GetTouch(0); transform.position = Camera.main.ScreenToWorldPoint(touch.position); } } 

    And what frameworks to set you decide the task yourself.

    And do not throw, please, the code in the screenshots. It is forbidden.

    • Hello. When using such a code, the object flies to the corner of the screen and takes a negative value along Z, which is why it is not visible. The effect of any movement also disappears, it simply moves the object: imgur.com/RxXEdQG - Eniwent
    • question: what kind of object is it at all? Is this a sprite on the canvas? Or something different? - Andrew
    • Hello. "Pole" and "Obj" is an Image. Game Object - according to its name. - Eniwent

    Because MousePos doesn’t have world coordinates, so it’s needed:

     transform.position = Vector3.Lerp(start.position, Camera.main.ScreenToWorldPosition(MousePos), Time.time / ariiveTime); 
    • Hello. When using this code (only Point instead of Position), the object flies to the corner of the screen and takes a negative value along Z, which is why it is not visible. The effect of any movement also disappears, it simply moves the object: imgur.com/RxXEdQG - Eniwent
    • Well, apparently you use some other camera, and not the one that is registered in Camera.main . Make a link in the script to the camera through which you are viewing and already for it do the calculation of the position of the object - KingPeas pm