-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBodyCamera.gd
41 lines (31 loc) · 1010 Bytes
/
BodyCamera.gd
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
31
32
33
34
35
36
37
38
39
40
41
extends Camera2D
export var zoom_amount = 1.2
func _ready():
pass
func _process(delta):
# Arrow Inputs
if Input.is_key_pressed(KEY_UP):
self.position.y -= 10
# print("Hello")
if Input.is_key_pressed(KEY_DOWN):
self.position.y += 10
# print("Bellow")
if Input.is_key_pressed(KEY_LEFT):
self.position.x -= 10
if Input.is_key_pressed(KEY_RIGHT):
self.position.x += 10
func _input(event):
if (event is InputEventMouseMotion) and Input.is_mouse_button_pressed(BUTTON_MIDDLE):
position -= event.relative * zoom[0]
if event is InputEventMouseButton:
if event.is_pressed():
#zoom in
if event.button_index == BUTTON_WHEEL_UP:
zoom /= zoom_amount
#Camera shift to account for zoom
position += (get_global_mouse_position() - position) * (zoom_amount - 1)
#zoom out
if event.button_index == BUTTON_WHEEL_DOWN:
#Camera shift to account for zoom
position -= (get_global_mouse_position() - position) * (zoom_amount - 1)
zoom *= zoom_amount