24 lines
778 B
GDScript3
24 lines
778 B
GDScript3
![]() |
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
|
||
|
|
||
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||
|
func _process(delta):
|
||
|
|
||
|
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
|
||
|
|