-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCameraMap.gd
96 lines (80 loc) · 2.24 KB
/
CameraMap.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
extends Camera
enum CameraMode {
UNIT_TRACK,
ISOMETRIC
}
var cameraMode = CameraMode.ISOMETRIC
var unitToTrack = null
func trackUnit(unit):
unitToTrack = unit
pass
func _ready():
set_process_input(true)
#Called when the node is added to the scene for the first time.
# Initialization here
pass
var speed = 50
var offset = Vector3()
func _input(event):
if event is InputEventMouseButton:
if event.is_pressed(): # zoom in
if event.button_index == BUTTON_WHEEL_UP:
scrollup = true
# call the zoom function
# zoom out
if event.button_index == BUTTON_WHEEL_DOWN:
scrolldown = true
var scrollup = false
var scrolldown = false
var firstTick = true
func _physics_process(delta):
offset = Vector3(0, 0, 0)
var pos = global_transform.origin
var target = pos + Vector3(0, -1, 0)
#print(pos)
#print(target)
var up = Vector3(1, 1, 0)
if firstTick:
look_at_from_position(Vector3(0, 200, 0), target, up)
firstTick = false
else:
look_at_from_position(pos, target, up)
rotate(Vector3(0, 1, 0), deg2rad(90))
if Input.is_action_pressed("ui_left"): # ui_left
offset.x -= 1
if Input.is_action_pressed("ui_right"): #ui_right
offset.x += 1
if Input.is_action_pressed("ui_up"): #ui_up
offset.y += 1
#offset.z -= 1
if Input.is_action_pressed("ui_down"): #ui_down
offset.y -= 1
#offset.z += 1
if Input.is_action_pressed("scroll_out") or scrolldown == true:
offset.z -= 1
if Input.is_action_pressed("scroll_in") or scrollup == true:
offset.z += 1
scrollup = false
scrolldown = false
# if event is InputEventMouseButton:
# if event.is_pressed(): # zoom in
# if event.button_index == BUTTON_WHEEL_UP:
# zoom_pos = get_global_mouse_position()
# # call the zoom function
# # zoom out
# if event.button_index == BUTTON_WHEEL_DOWN:
# zoom_pos = get_global_mouse_position()
# #call the zoom function
#offset = offset.normalized()
offset = offset * speed * delta
self.translate(offset)
self.size += offset.z
# rotation
# var pos = global_transform.origin
var target2 = pos + Vector3(0, -1, -1).normalized()
# look_at_from_position(pos, target2, up)
# Turn a little up or down
#var t = transform
#t.basis = Basis(t.basis[0], deg2rad(angle_v_adjust))*t.basis
#transform = t
# pos = target + delta