Periodic boundary now applies to prey too

This commit is contained in:
2026-01-02 13:17:55 +01:00
parent 3262a8899c
commit 4160361145
5 changed files with 32 additions and 15 deletions

View File

@@ -0,0 +1,19 @@
extends Node
var screen_size = Vector2(1920.0, 1080.0) # Default screen size (this is a float for some reason)
# TODO: This needs to be called from a script inheriting a CharacterBody2D (e.g. the player)
# Alternative would be to pass the player reference to this script (which might be better?)
func init_screen_size(x:float, y:float) -> void:
screen_size.x = x
screen_size.y = y
# This can take a vector of any size (but should be 2d, other components are unused)
func get_boundaried_position(position):
## clamp
#return position.clamp(Vector2.ZERO, screen_size)
## periodic
position.x = wrapf(position.x, 0, screen_size.x)
position.y = wrapf(position.y, 0, screen_size.y)
return position