Position Checking different in playing?

Godot Version

4.3

Question

Im trying to set a limit to where my Player/Slime can be dragged. I wanted to check the position of the worldborder and if the touch position is not within the limits it should ignore the movement. My Problem is that the Border is at Position 76 and when I print it it says 76 but It cant be 76 because when I print my Player Position and go to that Position its clearly not there.

Code for Movement

func _input(event):
	if areaEnt == true:
		if event is InputEventScreenTouch and event.is_pressed():
			touchPos = event.get_position()
			deltaX = touchPos.x - position.x
		
		elif event is InputEventScreenDrag:
			touchPos = event.get_position()
			newDeltaX = touchPos.x - deltaX
			BorderLeftX = GlobalSingletonPlayerBorder.BorderLeftX
			BorderRightX = GlobalSingletonPlayerBorder.BorderRightX
			if touchPos.x > BorderLeftX and touchPos.x < BorderRightX:
				print(touchPos)
				print(BorderRightX)
				set_position(Vector2(newDeltaX, position.y))
				JumpMechanic()

I think you might be misinterpreting global coordinate system vs viewport coordinates. See here my reply to another post, where I explained the difference, the same could apply to your scenario:

When I use .position isnt that the Viewport Coords ?

If you’re asking about the InputEventScreenDrag.position, then it is in the viewport coordinate system.

I think you’d need to share a short video of the issue you have, otherwise it’s hard to understand what you mean by the player being in the wrong position.

Well I fixed it with a different solution. but basically I compared if the InputEventScreenDrag.position.x is bigger than the Border.position.x and its probably because of what you said with the Viewport and the global coordinates

1 Like