camera: lint
This commit is contained in:
parent
79fa813571
commit
d00cee752e
1 changed files with 21 additions and 27 deletions
|
|
@ -2,74 +2,68 @@ 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 shift_lock = false
|
||||||
|
@export var default_zoom = 8
|
||||||
|
|
||||||
var locked_mouse_positon = Vector2(0,0)
|
|
||||||
var mouse_locked = false
|
var mouse_locked = false
|
||||||
var mouse_x_velocity = 0
|
var mouse_velocity = Vector2.ZERO
|
||||||
var mouse_y_velocity = 0
|
var locked_mouse_position = Vector2.ZERO
|
||||||
|
|
||||||
|
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
|
||||||
var current_zoom = 8
|
|
||||||
|
|
||||||
func reset():
|
func reset():
|
||||||
basis = Basis()
|
basis = Basis()
|
||||||
$InnerGimbal.basis = Basis()
|
$InnerGimbal.basis = Basis()
|
||||||
|
current_zoom = default_zoom
|
||||||
|
|
||||||
func rotate_camera_y(y, delta):
|
func rotate_camera_y(y, delta):
|
||||||
rotate_object_local(Vector3.UP, y * rotation_speed * delta)
|
rotate_object_local(Vector3.UP, y * rotation_speed * delta)
|
||||||
func rotate_camera_x(x, 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)
|
||||||
|
|
||||||
func _input(event):
|
func _input(event):
|
||||||
if event is InputEventMouseMotion:
|
if event is InputEventMouseMotion:
|
||||||
mouse_x_velocity = event.relative.x
|
mouse_velocity = event.relative
|
||||||
mouse_y_velocity = event.relative.y
|
|
||||||
elif event.is_action_pressed("zoom_out"):
|
elif event.is_action_pressed("zoom_out"):
|
||||||
current_zoom += 1
|
current_zoom += 1
|
||||||
elif event.is_action_pressed("zoom_in"):
|
elif event.is_action_pressed("zoom_in"):
|
||||||
current_zoom -= 1
|
current_zoom -= 1
|
||||||
|
|
||||||
|
current_zoom = clamp(current_zoom, zoom_min, zoom_max)
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
# rotate outer gimbal around y axis
|
|
||||||
var y = 0
|
var y = 0
|
||||||
var x = 0
|
var x = 0
|
||||||
|
|
||||||
if Input.is_action_just_pressed("shift_lock"):
|
if Input.is_action_just_pressed("shift_lock"):
|
||||||
if shift_lock == true:
|
shift_lock = not shift_lock
|
||||||
shift_lock = false
|
if Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT) or shift_lock == true:
|
||||||
else:
|
|
||||||
shift_lock = true
|
|
||||||
elif Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT) or shift_lock == true:
|
|
||||||
if mouse_locked == false:
|
if mouse_locked == false:
|
||||||
mouse_locked = true
|
mouse_locked = true
|
||||||
locked_mouse_positon = get_viewport().get_mouse_position()
|
locked_mouse_position = get_viewport().get_mouse_position()
|
||||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||||
|
|
||||||
if mouse_x_velocity > 5 or mouse_x_velocity < -5:
|
if mouse_velocity.x > 5 or mouse_velocity.x < -5:
|
||||||
y -= clamp(mouse_x_velocity / 12.5, -10, 10)
|
y -= clamp(mouse_velocity.x / 12.5, -10, 10)
|
||||||
if mouse_y_velocity > 5 or mouse_y_velocity < -5:
|
if mouse_velocity.y > 5 or mouse_velocity.y < -5:
|
||||||
x -= clamp(mouse_y_velocity / 12.5, -10, 10)
|
x -= clamp(mouse_velocity.y / 12.5, -10, 10)
|
||||||
else:
|
else:
|
||||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||||
|
mouse_velocity = Vector2.ZERO
|
||||||
mouse_locked = false
|
mouse_locked = false
|
||||||
mouse_x_velocity = 0
|
|
||||||
mouse_y_velocity = 0
|
|
||||||
|
|
||||||
rotate_camera_y(y, delta)
|
rotate_camera_y(y, delta)
|
||||||
rotate_camera_x(x, delta)
|
rotate_camera_x(x, delta)
|
||||||
|
|
||||||
# reset gimbals
|
|
||||||
if Input.is_action_pressed("cam_reset"):
|
if Input.is_action_pressed("cam_reset"):
|
||||||
reset()
|
reset()
|
||||||
|
|
||||||
current_zoom = clamp(current_zoom, zoom_min, zoom_max)
|
|
||||||
|
|
||||||
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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue