I found a lesson where the smooth movement of physical objects around the map is done using buttons. I decided to make it possible to move only with the mouse (that is, where the cursor is looking, there is an object). But when I aim at an object, it flies to the side of the cursor. Rigidbody and BoxCollider stand at the facility itself. Cave is the ground on which the object moves.

using UnityEngine; //эта строчка гарантирует что наш скрипт не завалится ести на плеере будет отсутствовать компонент Rigidbody [RequireComponent(typeof(Rigidbody))] public class Movement : MonoBehaviour { // т.к. логика движения изменилась мы выставили меньшее и более стандартное значение public float Speed = 1f; //что бы эта переменная работала добавьте тэг "Ground" на вашу поверхность земли float raycastLeight = 100; private Rigidbody _rb; RaycastHit _hit; private Vector3 movement; void Start() { _rb = GetComponent<Rigidbody>(); } void FixedUpdate() { if (GlobalVar.activeCreateUnit == true) { GameObject _target = GameObject.FindWithTag("CreateUnit"); Ray _ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(_ray, out _hit, raycastLeight)) { if ((_hit.collider.name == "Cave") && (_target != null)) { // в даном случае допустимо использовать это здесь, но можно и в Update. // но раз уж вызываем здесь, то // двигать будем используя множитель fixedDeltaTimе MovementLogic(); } if ((GlobalVar.onTriggerUnit == false)&&(Input.GetMouseButton(0))) { GlobalVar.activeCreateUnit = false; } if(Input.GetMouseButton(1)) { Destroy(_target); } } } } private void MovementLogic() { Vector3 mousePosition = new Vector3(Input.mousePosition.x, 0, Input.mousePosition.y); movement = Camera.main.ScreenToWorldPoint(mousePosition); movement = new Vector3(movement.x, 0, movement.z); // что бы скорость была стабильной в любом случае // и учитывая что мы вызываем из FixedUpdate мы умножаем на fixedDeltaTimе transform.Translate(movement * Speed * Time.fixedDeltaTime); } } 
  • it is not clear what you want to get in the end. Moving object by mouse movement? Teleportation of the object to the place of the click? Smooth moving to the click place? Well describe what you want to get in practice. - Andrew
  • And the article is the one from which you took the code not to copy the code from there, but just to show the main mistakes or what you can do. For example, in the following script, the implementation of IsGrounded was better for which it would be worth paying attention to. - Andrew
  • To implement, I want the object to move behind the mouse cursor and keep up with it. - Igor Fedorov
  • I do not need a jump there, I removed it, I need to just go smoothly on the ground with the help of the cursor - Igor Fedorov

0