camera: remove shift lock
This commit is contained in:
parent
35a17c04b6
commit
54967e570b
2 changed files with 47 additions and 34 deletions
|
|
@ -1,26 +1,52 @@
|
||||||
class_name CameraGimbal extends Node3D
|
class_name CameraGimbal extends Node3D
|
||||||
|
|
||||||
@export var rotation_speed = (PI / 180) * 120
|
@export var rotation_speed = (PI / 180) * 120
|
||||||
@export var shift_lock = false
|
|
||||||
@export var default_zoom = 8
|
@export var default_zoom = 8
|
||||||
|
|
||||||
var mouse_locked = false
|
# is mouse captured by game permanently?
|
||||||
|
# (i.e. not just holding right click)
|
||||||
|
var locked = false
|
||||||
var mouse_velocity = Vector2.ZERO
|
var mouse_velocity = Vector2.ZERO
|
||||||
var locked_mouse_position = Vector2.ZERO
|
|
||||||
|
|
||||||
var current_zoom = default_zoom
|
var current_zoom = default_zoom
|
||||||
var zoom_min = 4
|
var zoom_min = 4
|
||||||
var zoom_max = 80
|
var zoom_max = 80
|
||||||
var zoom_speed = 20
|
var zoom_speed = 20
|
||||||
|
|
||||||
|
func _lock():
|
||||||
|
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||||
|
|
||||||
|
func _unlock():
|
||||||
|
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||||
|
mouse_velocity = Vector2.ZERO
|
||||||
|
|
||||||
|
func lock():
|
||||||
|
_lock()
|
||||||
|
locked = true
|
||||||
|
|
||||||
|
# optional API function for nodes that want
|
||||||
|
# to unlock the mouse for a period of time
|
||||||
|
func unlock():
|
||||||
|
_unlock()
|
||||||
|
locked = false
|
||||||
|
|
||||||
func reset():
|
func reset():
|
||||||
basis = Basis()
|
basis = Basis()
|
||||||
$InnerGimbal.basis = Basis()
|
$InnerGimbal.basis = Basis()
|
||||||
current_zoom = default_zoom
|
current_zoom = default_zoom
|
||||||
|
|
||||||
func rotate_camera_y(y, delta):
|
# y is before x because the outer gimbal is
|
||||||
|
# in charge of rotating the y axis
|
||||||
|
func rotate_camera(delta):
|
||||||
|
var y = 0
|
||||||
|
var x = 0
|
||||||
|
|
||||||
|
if mouse_velocity.x > 5 or mouse_velocity.x < -5:
|
||||||
|
y -= clamp(mouse_velocity.x / 12.5, -10, 10)
|
||||||
|
if mouse_velocity.y > 5 or mouse_velocity.y < -5:
|
||||||
|
x -= clamp(mouse_velocity.y / 12.5, -10, 10)
|
||||||
|
|
||||||
rotate_object_local(Vector3.UP, y * rotation_speed * delta)
|
rotate_object_local(Vector3.UP, y * rotation_speed * delta)
|
||||||
func rotate_camera_x(x, delta):
|
|
||||||
$InnerGimbal.rotate_object_local(
|
$InnerGimbal.rotate_object_local(
|
||||||
Vector3.RIGHT, x * rotation_speed * delta)
|
Vector3.RIGHT, x * rotation_speed * delta)
|
||||||
$InnerGimbal.rotation.x = clamp($InnerGimbal.rotation.x, -0.8, 0.7)
|
$InnerGimbal.rotation.x = clamp($InnerGimbal.rotation.x, -0.8, 0.7)
|
||||||
|
|
@ -36,34 +62,26 @@ func _input(event):
|
||||||
current_zoom = clamp(current_zoom, zoom_min, zoom_max)
|
current_zoom = clamp(current_zoom, zoom_min, zoom_max)
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
var y = 0
|
# rotate camera
|
||||||
var x = 0
|
if locked:
|
||||||
|
rotate_camera(delta)
|
||||||
if Input.is_action_just_pressed("shift_lock"):
|
|
||||||
shift_lock = not shift_lock
|
|
||||||
if Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT) or shift_lock == true:
|
|
||||||
if mouse_locked == false:
|
|
||||||
mouse_locked = true
|
|
||||||
locked_mouse_position = get_viewport().get_mouse_position()
|
|
||||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
|
||||||
|
|
||||||
if mouse_velocity.x > 5 or mouse_velocity.x < -5:
|
|
||||||
y -= clamp(mouse_velocity.x / 12.5, -10, 10)
|
|
||||||
if mouse_velocity.y > 5 or mouse_velocity.y < -5:
|
|
||||||
x -= clamp(mouse_velocity.y / 12.5, -10, 10)
|
|
||||||
else:
|
else:
|
||||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
if Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT):
|
||||||
mouse_velocity = Vector2.ZERO
|
_lock()
|
||||||
mouse_locked = false
|
rotate_camera(delta)
|
||||||
|
else:
|
||||||
rotate_camera_y(y, delta)
|
_unlock()
|
||||||
rotate_camera_x(x, delta)
|
|
||||||
|
|
||||||
if Input.is_action_pressed("cam_reset"):
|
|
||||||
reset()
|
|
||||||
|
|
||||||
|
# zoom in/out
|
||||||
var pos = Vector3($InnerGimbal/Camera3D.position)
|
var pos = Vector3($InnerGimbal/Camera3D.position)
|
||||||
pos.y = lerp(pos.y, float(current_zoom), zoom_speed * delta)
|
pos.y = lerp(pos.y, float(current_zoom), zoom_speed * delta)
|
||||||
pos.z = lerp(pos.z, float(current_zoom), zoom_speed * delta)
|
pos.z = lerp(pos.z, float(current_zoom), zoom_speed * delta)
|
||||||
|
|
||||||
$InnerGimbal/Camera3D.position = pos
|
$InnerGimbal/Camera3D.position = pos
|
||||||
|
|
||||||
|
# reset camera
|
||||||
|
if Input.is_action_pressed("cam_reset"):
|
||||||
|
reset()
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
lock()
|
||||||
|
|
|
||||||
|
|
@ -67,11 +67,6 @@ backpack_3={
|
||||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":51,"physical_keycode":0,"key_label":0,"unicode":51,"location":0,"echo":false,"script":null)
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":51,"physical_keycode":0,"key_label":0,"unicode":51,"location":0,"echo":false,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
shift_lock={
|
|
||||||
"deadzone": 0.2,
|
|
||||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194325,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
|
||||||
]
|
|
||||||
}
|
|
||||||
cam_zoom_in={
|
cam_zoom_in={
|
||||||
"deadzone": 0.2,
|
"deadzone": 0.2,
|
||||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":4,"canceled":false,"pressed":false,"double_click":false,"script":null)
|
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":4,"canceled":false,"pressed":false,"double_click":false,"script":null)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue