How in Unity to make Rigidbody move to the given coordinates with a given force? Like MoveTo, but with the ability to set the strength of the movement?

AddForce.forward + rotation is not suitable, because the body must first be rotated, but in this case is not an option.

Closed due to the fact that the essence of the question is incomprehensible by the participants Alexey Shimansky , HamSter , cheops , Denis , Grundy 30 Sep '16 at 9:21 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Gentlemen minus, explain the reason at least. The question is inaccurately worded, need additional clarification or is it too common? I met a similar question only in the English version. answers.unity3d.com/questions/444761/... The solution provided there does not work for me. Comment please. - Dmitrii

1 answer 1

Everything turned out to be quite simple.

The variant from the English-language source did not fit, since it was intended for a script that was attached to a moving object. Hence the use of transform.position .

In my case, the control script is hanging on another object.

Therefore, the script looks like this.

  if (Input.GetMouseButton(0)) { ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit) && hit.collider.CompareTag("fishka")) { Collider col = hit.collider; var dir = (hit.point - col.transform.position); // Используем координаты коллайдера rot.z = hit.point.z; rot.x = hit.point.x; col.attachedRigidbody.velocity = new Vector3(dir.x, 0, dir.z) * speed; Debug.Log(hit.point + " hitpoint"); Debug.Log(transform.position + " transform.position");