Moving UI image based on the player movement, in 1:1 ratio in scene

I have a 2D game in unity. I want the UI image (that is in canvas object), to move over the player/enemy gameobject.

With my script, the UI image moves but it is way slower that the ship , like the transform of gameobject is not the same as the UI image.

Here is my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ClampUIonPlayer : MonoBehaviour
{
    public Image img;

    Camera cam;

    public Canvas canvas;



    private void Start()
    {
        cam = GameObject.Find("FullScaleRadarCamera").GetComponent<Camera>();

    }

    // Update is called once per frame
    void Update()
    {

        Vector3 imgVec = cam.WorldToScreenPoint(this.transform.position);
        //img.transform.position = imgVec;

        Vector2 movePos;

        //Convert the screenpoint to ui rectangle local point
        RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform, imgVec, canvas.worldCamera, out movePos);
        img.transform.position = movePos;
        Debug.Log(movePos);

    }



}

Player’s ship contains this script. UI image is placed inside the Canvas. The UI image is displayed only on the second samera (I am doing all of this so that I can display the UI images of players in my game, in minimap. But I need to use UI images, not just the second camera, because I need to have the hover over effect on the players on the minimap. The hover over effect cant seem to work in second camera, with raycast, for standard game objects).

Here is my scene: https://photos.app.goo.gl/UoLtTu4mKXffq7UBA

Here is a video of my problem. The selected ship is the green box, the other ships, faster one, is the red box. I control them both at the same time. UI icons dont move 1:1 with these ships.https://photos.app.goo.gl/hXu8aV2UFfcZzBoC6

Thank you for any help.

I have tried this solution to the problem c# - Move UI RectTransform to world position - Stack Overflow I copied the script as it was but the UI images wont move separately , they move as one for some reason.

The first part of the movement

Vector3 imgVec = cam.WorldToScreenPoint(this.transform.position);

Is all you should need; after that just set the GameObjects location and it should be fine.

I’m not sure what the whole rectangle thing is about?

Nope that does not work. If I do that , the UI images are shifted to the side,they dont hover over the game object when I hit the play, (in inspector they are set with exact the same position as the ships)
And they move like 3 times slower too.
Here is the script. (tried this before, thats why I need to use rectangle).

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ClampUIonPlayer : MonoBehaviour
{
    public Image img;

    Camera cam;

    public Canvas canvas;



    private void Start()
    {
        cam = GameObject.Find("FullScaleRadarCamera").GetComponent<Camera>();

    }

    // Update is called once per frame
    void Update()
    {

        Vector3 imgVec = cam.WorldToScreenPoint(this.transform.position);
        img.transform.position = imgVec;

          
    }



}

You can add offsets to the Vector3 to fine tune it to the correct position.

What speed do the ships move at?

Not sure what are you asking. The ships accelerate gradually until they reach their top speed, but that takes like 10 seconds.

Are the health bars always behind? Even if you’ve just started moving?
This seems like it’s limited by your FPS

No, it is not limited by my FPS. The health bars are not behind at the beginning. They always match the position of the ship at the start. Only when the ships move, they lag behind , their movement is not 1:1 but 3:1.
1 square in inspector for the icon is 3 squares for ship.