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.
