-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMoving_Icon.gd
More file actions
30 lines (21 loc) · 757 Bytes
/
Moving_Icon.gd
File metadata and controls
30 lines (21 loc) · 757 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
extends Control
var speed = 200
var direction = Vector2(1,1) #move diagonally
func _ready():
randomize()
direction.x = rand_range(-1.0,1.0)
direction.y = rand_range(-1.0,1.0)
func _process(delta):
var viewport_rect = get_viewport_rect()
if rect_global_position.x <= 0:
direction.x = rand_range(0,1)
if rect_global_position.x + rect_size.x >= viewport_rect.size.x:
direction.x = rand_range(-1,0)
if rect_global_position.y <= 0:
direction.y = rand_range(0,1)
if rect_global_position.y + rect_size.y >= viewport_rect.size.y:
direction.y = rand_range(-1,0)
var position_change = Vector2.ZERO
position_change.x = direction.x * speed * delta
position_change.y = direction.y * speed * delta
rect_global_position += position_change