Overhauled camera
This commit is contained in:
parent
5fe8f22ccb
commit
da78e7f287
21 changed files with 385 additions and 71 deletions
77
CameraPivot.gd
Normal file
77
CameraPivot.gd
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
extends Node3D
|
||||
|
||||
@onready var azimuth_pivot = $AzimuthPivot
|
||||
|
||||
@onready var spring_arm_3d = $AzimuthPivot/SpringArm3D
|
||||
|
||||
var zoom_tween: Tween
|
||||
|
||||
var min_zoom_distance: float = 2.0
|
||||
var max_zoom_distance: float = 10.0
|
||||
|
||||
var min_camera_angle: float = 15.0
|
||||
var max_camera_angle: float = 75.0
|
||||
|
||||
var rotating: bool = false
|
||||
var rotate_2d_position: Vector2 = Vector2.ZERO
|
||||
var rotate_2d_position_old: Vector2 = Vector2.ZERO
|
||||
var old_y_rotation: float = 0.0
|
||||
var old_x_rotation: float = 0.0
|
||||
|
||||
@onready var camera = $AzimuthPivot/SpringArm3D/Camera
|
||||
|
||||
var world_distance_limit: float = 25.0
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
if Input.is_action_just_pressed("zoom_camera_in"):
|
||||
if zoom_tween != null:
|
||||
zoom_tween.kill()
|
||||
zoom_tween = get_tree().create_tween()
|
||||
var new_dist = clamp(spring_arm_3d.spring_length / 1.2, min_zoom_distance, max_zoom_distance)
|
||||
zoom_tween.tween_property(spring_arm_3d, "spring_length", new_dist, 0.25)
|
||||
#spring_arm_3d.spring_length -= 0.5
|
||||
if Input.is_action_just_pressed("zoom_camera_out"):
|
||||
if zoom_tween != null:
|
||||
zoom_tween.kill()
|
||||
zoom_tween = get_tree().create_tween()
|
||||
var new_dist = clamp(spring_arm_3d.spring_length * 1.2, min_zoom_distance, max_zoom_distance)
|
||||
zoom_tween.tween_property(spring_arm_3d, "spring_length", new_dist, 0.25)
|
||||
#spring_arm_3d.spring_length += 0.5
|
||||
|
||||
if Input.is_action_just_pressed("rotate_camera"):
|
||||
rotating = true
|
||||
# get screen position of cursor?
|
||||
rotate_2d_position = get_viewport().get_mouse_position()
|
||||
rotate_2d_position_old = get_viewport().get_mouse_position()
|
||||
old_y_rotation = rotation.y
|
||||
old_x_rotation = azimuth_pivot.rotation.x
|
||||
if Input.is_action_just_released("rotate_camera"):
|
||||
rotating = false
|
||||
|
||||
if rotating:
|
||||
rotate_2d_position = get_viewport().get_mouse_position()
|
||||
var mouse_diff = rotate_2d_position - rotate_2d_position_old
|
||||
rotation.y = old_y_rotation - mouse_diff.x * 0.005
|
||||
azimuth_pivot.rotation.x = old_x_rotation - mouse_diff.y * 0.005
|
||||
pass
|
||||
|
||||
if Input.is_action_pressed("camera_left"):
|
||||
position -= transform.basis.x * 0.2
|
||||
if Input.is_action_pressed("camera_right"):
|
||||
position += transform.basis.x * 0.2
|
||||
|
||||
if Input.is_action_pressed("camera_up"):
|
||||
position -= transform.basis.z * 0.2
|
||||
if Input.is_action_pressed("camera_down"):
|
||||
position += transform.basis.z * 0.2
|
||||
|
||||
if position.length() > world_distance_limit:
|
||||
position = position.normalized() * world_distance_limit
|
||||
|
||||
|
||||
|
||||
if azimuth_pivot.rotation_degrees.x > -min_camera_angle:
|
||||
azimuth_pivot.rotation_degrees.x = -min_camera_angle
|
||||
if azimuth_pivot.rotation_degrees.x < -max_camera_angle:
|
||||
azimuth_pivot.rotation_degrees.x = -max_camera_angle
|
||||
Loading…
Add table
Add a link
Reference in a new issue