Trying to move my object in another object's position

For some reason player doesn’t move in the middle of the block, but stops when reaches the side of the block.
FindBlockToMove() is just a spot, but it has a child visual object with a collider. player is also just a spot and it has a child visual object. Visual objects of player and block are not touching.
Why can it happen and what should I do to make player move in the middle of the block?
And it happens both with MoveTowards and with Lerp

private void MoveToChosenBlock()
{
GameObject _blockToMove = FindBlockToMove();
Debug.Log($“Now we move to {_blockToMove}”);
float _moveDistance = _moveSpeed * Time.deltaTime;
Vector3 _blockPosition = FindBlockToMove().transform.position;

transform.position = Vector3.MoveTowards(transform.position, _blockPosition, _moveDistance);
//transform.position = Vector3.Lerp(transform.position, _blockPosition, 0.1f);
}

This is a scripting issue. Since you’re using transform.position, it’s not a physics question at all. Maybe a mod will move this thread appropriately. And next time, use the code tags to format your scripts here.

All of your code looks fine for moving at a set speed toward the destination, but you will have to call MoveToChosenBlock() on every Update() until it reaches the chosen block.

1 Like

Thank you! This is my first post here, so I was a lil bit confused…

I do call this method in Update, and player moves. But it stops when it touches the side of a visual part of block and I want it to move to the block’s position which is in the middle of it’s visual part. I see, it’s hard to explain without a video

I guess it was happening because of Raycast which I was using for searching for blocks. I fixed this by separating FindBlockToMove() method from the method MoveToChosenBlock() .