27 lines
856 B
GDScript
27 lines
856 B
GDScript
class_name Target extends Node3D
|
|
|
|
@export var moveSpeed: float = 100
|
|
|
|
@export_group("Movements Bounds")
|
|
@export var topBound: float
|
|
@export var bottomBound: float
|
|
@export var leftBound: float
|
|
@export var rightBound: float
|
|
|
|
var controlling: bool = true
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta):
|
|
if (!City.moving || !City.controlling): return
|
|
|
|
var horizontalMovement: float = Input.get_axis("right", "left")
|
|
var verticalMovement: float = Input.get_axis("down", "up")
|
|
|
|
position.x += horizontalMovement * moveSpeed * delta
|
|
position.y += verticalMovement * moveSpeed * delta
|
|
if (position.x < leftBound): position.x = leftBound
|
|
elif (position.x > rightBound): position.x = rightBound
|
|
if (position.y < bottomBound): position.y = bottomBound
|
|
elif (position.y > topBound): position.y = topBound
|
|
|