i would be thankfull if somone would help
thanks! (btw im still a noob in coding)
You use two process functions and thats not possible.
Try this:
extends Sprite2D
func _process(delta: float):
position = get_global_mouse_position()
if position.x > 200:
position.x = 200
But I think you want to set more than only the maximum for X.
In this case try something like this:
extends Sprite2D
func _process(delta: float):
position = get_global_mouse_position()
# Clamp X-axis (left/right boundaries)
position.x = clamp(position.x, 50, 200) # Min x=50, Max x=200
# Optional: Clamp Y-axis (up/down boundaries)
position.y = clamp(position.y, 100, 400) # Min y=100, Max y=400
You can change the Min and Max for both (X and Y) with this.
2 Likes
Ty so much!
I think there’s an error because the code below it, is probably using spaces instead of indents?
I think you used spaces because i don’t see an arrow on the left side of your code
The editor can be configure to use spaces instead of tabulator characters (tabs or \t
if you use it in a string and have to escape it). It’s in the editor settings under Text Editor -> Behaviour
and showing those indentation characters as dots, arrow or not at all is under Text Editor -> Appearance
.
1 Like