40 lines
964 B
GDScript
40 lines
964 B
GDScript
extends Node2D
|
|
|
|
@onready var area_2d: Area2D = $Area2D
|
|
@onready var camera: Camera2D = $Camera2D
|
|
|
|
@export var should_follow_player = false
|
|
@export var minimum_location = 0
|
|
@export var maximum_location = 640
|
|
|
|
|
|
var is_player_in_range = false
|
|
var player: Node2D
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
pass # Replace with function body.
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta: float) -> void:
|
|
if not should_follow_player or not is_player_in_range:
|
|
return
|
|
|
|
if player.global_position.x < minimum_location or player.global_position.x > maximum_location:
|
|
return
|
|
|
|
global_position.x = player.global_position.x
|
|
|
|
|
|
func _on_body_entered(body: Node2D) -> void:
|
|
if body.name == "Player":
|
|
camera.make_current()
|
|
player = body
|
|
is_player_in_range = true
|
|
|
|
|
|
func _on_body_exited(body: Node2D) -> void:
|
|
if body.name == "Player":
|
|
is_player_in_range = false
|