Godot Version 3.5
Hello friends
I am new to Godot
I want to use a rectangle as something like a touch pad, and move a brush across the phone screen.
Touch does not work outside the orange area
My problem is how to detect relative touch position on rectangle
Does anyone have any ideas on this?
touch_position - rectangle_position
1 Like
Thanks for your reply herrspaten
I’m not talking about calculating the touched point, I want to know if there is an object to get the touch coordinates on?
Do you mean an InputEvent?
func _input(event) -> void:
if(event is InputEventScreenTouch):
if (event.pressed()):
position = event.position
I looking for an object, Imagine a button that reports the coordinates of which point of it was pressed
Yes you can use a button and then take the signal: gui_input(event), to determine where it has been clicked
Do you mean that with this function it is possible to determine whether point 1 or 2 is pressed in the attached image?
Can you give an example of a piece of code?

func _input(event) -> void:
if(event is InputEventScreenTouch):
if (event.pressed()):
touch_position= event.position
this will give you the touch_position on the button. If you want to check for certain rectangles inside the button you would have to check if this touch position is inside the given rectangle
Note: this position is the position on the viewport. To get the local_position of the touch you have to subtract it:
touch_position - button_position
This means that it is not possible to get touch coordinates on a specific object and it must be calculated based on the coordinates of the entire screen.
In fact, I wanted the painting button to be pressed at the same time as the brush moves and…
I think I should go for multi-touch
Whats wrong with calculating it based on the coordinates of the entire screen?
I thought that if I could get the absolute coordinates of touching and dragging on an object, I would no longer need multi-touch and it would be easier.
Right part for brush movement and left part for paint
Im a little confused about what you want to achieve. In your original post you want the relative touch position of the rectangle → the code gives you the relative touch position. What exactly is your problem with the calculation?
In my temporary project, when the right hand is moving the brush, if the left hand touches the screen, the brush moves to the other side of the screen and is controlled by the left hand.
extends Node2D
var s = Vector2(0,0)
func _input(event):
if event is InputEventScreenTouch:
if event.pressed and event.index == 1:
$LBL_2.text = "Painting"
if event is InputEventScreenTouch:
if event.pressed and event.index == 0:
s = event.position
$LBL_1.text = "X:"+str(s.x) + "_" + "Y:"+str(s.y)
elif event is InputEventScreenDrag:
s = event.position
$SPR_brush.global_position = s
$LBL_1.text = "X:"+str(s.x) + "_" + "Y:"+str(s.y)
Okay, now i get it. I still thought the problem was the one in your first post. Yeah sounds like you need multi-touch
1 Like