Raycast Hit Offset Issue

Hi Everyone!

I’m currently stuck on what I thought was going to be an easy task and so far it’s been anything but that. It’s quite tricky to explain but ill do my best.

So I have a Target which the player moves to aim their projectile. The target has a handle above it for the player to interact with to move the target.

What I currently have is Raycast from the Mouse and the target moves there. This does work but the problem is that the target will snap to the hit point behind the Target Handle and the target moves back.

What I want is for the target not to move stay where it is until the player moves the Mouse and it updates nicly.

Here is a little illustration of what’s happening

You can get a better picture of what’s going on. I pick up the target using the handle and it moves back.

I’ve tried adding offsets and stuff but all have attempted has produced unreliable results.

Here is the current code:

private void UpdateTargetTest()
    {
        if (GolflxInput.GetPointerDown())
        {
            Ray checkRay = CoreManager.CameraManager.MainCamera.camera.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(checkRay, out _hit))
            {
                IsPickedUp = !CoreManager.PanelManager.IsPointerOverUIObject() &&
                             _hit.collider.CompareTag("Ground");
            }

        }

        if (GolflxInput.GetPointerUp() && IsPickedUp)
        {
            IsPickedUp = false;
        }
       
        if (IsPickedUp)
        {
            Ray ray = CoreManager.CameraManager.MainCamera.camera.ScreenPointToRay(Input.mousePosition);
           
            if (!Physics.Raycast(ray, out _hit, 1000, 1 << LayerMask.NameToLayer("Default"))) return;
           
            _targetPosition = _hit.point;
            OnUpdateTarget();
        }
    }

Again I feel like I’m missing a really simple solution to this. If anyone could help or point me in the right direction that would be very much appreciated.

If I’m understanding you correctly, couldn’t this be fixed by shifting the objects around the hierarchy so that the origin/pivot of the object is at the target marker’s bottom tip? That way, when you’re clicking to set the position and it displays the marker, it points exactly where you clicked?

That’s what I currently have implemented. The problem is your finger is covering where you’re aiming. So I want a handle above that you grab to move that.

Starting to think that a Raycast might not be the correct solution. Maybe I need to move the target with Mouse Input. And then only use a Raycast to stick it to the floor.