In the code below, when you click on an object (the fishka tag is assigned to it), the object flies away. Although I must go for a clamped mouse. Moreover, if you refuse from rigidbody and just instead
transform.GetComponent<Rigidbody>().AddForce(rot*0.1f,ForceMode.VelocityChange); put the usual
transform.position = rot; That is all ok, the object follows the clamped mouse.
private Ray ray; private RaycastHit hit; private Vector3 rot = new Vector3(0, 0, 0); void Update() { if (Input.GetMouseButton(0)) { ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit) && hit.collider.CompareTag("fishka")) { rot.z = hit.point.z; rot.x = hit.point.x; transform.GetComponent<Rigidbody>().AddForce(rot*0.1f, ForceMode.VelocityChange); } } } accordingly, the question is how to make it so that the rigidbody goes for the clamped mouse.
Here's what it looks like. First we move through transform.position, then through a rigidbody. https://youtu.be/cIrfZoRaWk4
FixedUpdate. Secondly, if you don't need something explosive / impulsive, then try and use arigidBody.velocity.....rb.velocity = rot*0.1f;something like this ...... or rather without*0.1fsince you are not using it without rigidbidy .... most likely it will not be necessary anyway - Alexey Shimanskytransform.GetComponent<Rigidbody>().position = rot;...... everything ...... only there should be norot.z = hit.point.z;androt.y = hit.point.y;as I understand. ...... and velocity and addforce are a bit different ............ and if you are using 2D, then it should be like a rigidbody2d - Alexey Shimanskytransform.GetComponent<Rigidbody>().MovePosition(rot);..... here's the difference fromtransform.GetComponent<Rigidbody>().position = rot;I can not tell. maybe not - Alexey Shimansky