Code that (edit: does not) works for a moving camera

This code (edit: does not work) to clamp the player’s position to the screen no matter how big or small you set your screen or whether the camera is moving.

func fix_player_position():
	var screen = get_viewport_rect()
	global_position = global_position.clamp(screen.position, screen.position + screen.size)

Enjoy!

-W

2 Likes

nice one, cheers for sharing :slight_smile:

Privacy & Terms