Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | smslv |
I have a viewport translating on a 3d sprite. On viewport I have a virtual cursor (which is 2d sprite) which I move with
public override void _Process(float delta)
{
var mousePosNew = GetViewport().GetMousePosition();
mouseAxis = mousePosNew - mousePosPrev;
mousePosPrev = mousePosNew;
cursorPos.x = Mathf.Clamp(cursorObj.Position.x + mouseAxis.x * cursorSpeed.x, cursorSize.x/2, screenSize.x - cursorSize.x/2);
cursorPos.y = Mathf.Clamp(cursorObj.Position.y + mouseAxis.y * cursorSpeed.y, cursorSize.y/2, screenSize.y - cursorSize.y/2);
cursorObj.Position = cursorPos;
}
At different occasions there will be different elements in a viewport, and I cannot know beforehand their positions, sizes and nodes. How would I check if my cursor is inside an element of this viewport to pass a click event to it?