edge scrolling
This commit is contained in:
parent
2e7c67b0ef
commit
47f874af52
1 changed files with 30 additions and 4 deletions
|
@ -8,8 +8,8 @@ extends Node3D
|
|||
@export_range(11,50,1) var zoom_max: float = 20
|
||||
@export_range(0,0.95,0.01) var zoom_speed_damp: float = 0.5
|
||||
|
||||
@export_range(0,32,4) var edge_scrolling_margin: int = 4
|
||||
@onready var edge_scrolling_speed: float = ProjectSettings.get_setting("game/controls/edge_scrolling_speed",20.0)
|
||||
@export_range(0,32,4) var edge_scrolling_margin: int = ProjectSettings.get_setting("game/controls/edge_scrolling_margin",8)
|
||||
@onready var edge_scrolling_speed: float = ProjectSettings.get_setting("game/controls/edge_scrolling_speed",25.0)
|
||||
|
||||
@onready var socket: Node3D = $camera_point
|
||||
@onready var cam : Camera3D = %camera_player
|
||||
|
@ -44,7 +44,7 @@ func cam_move(delta:float) -> void:
|
|||
if Input.is_action_pressed("cam_left"): velocity_direction -= transform.basis.z
|
||||
if Input.is_action_pressed("cam_right"): velocity_direction += transform.basis.z
|
||||
|
||||
position += velocity_direction.normalized() * delta * move_speed
|
||||
position += velocity_direction.normalized() * delta * move_speed * get_zoom_factor()
|
||||
|
||||
|
||||
## Controls the zoom of the player camera
|
||||
|
@ -61,5 +61,31 @@ func cam_zoom(delta:float) -> void:
|
|||
zoom_direction *= zoom_speed_damp #Smooth the deceleration
|
||||
|
||||
|
||||
func get_mouse_position() -> Vector2:
|
||||
return get_viewport().get_mouse_position()
|
||||
|
||||
|
||||
## multiplicator for movement speed, based on zoom level
|
||||
func get_zoom_factor() -> float:
|
||||
return remap(cam.position.z,zoom_min,zoom_max,0.1,2.0)
|
||||
|
||||
|
||||
func cam_edge_scroll(delta:float) -> void:
|
||||
pass
|
||||
if edge_scroll_disabled:return
|
||||
var current_viewport = get_viewport()
|
||||
var pan_direction := Vector2(0,0) #Edge scrolling to bottom left by default, changing that if needed
|
||||
var viewport_rectange := Rect2i(current_viewport.get_visible_rect())
|
||||
var viewport_size := viewport_rectange.size
|
||||
var mouse_position = get_mouse_position()
|
||||
|
||||
# X PAN
|
||||
if (mouse_position.x < edge_scrolling_margin or (mouse_position.x > viewport_size.x - edge_scrolling_margin)):
|
||||
pan_direction.x = 1 if (mouse_position.x > viewport_size.x/2) else -1 # detect if we are in the half of the screen or not
|
||||
|
||||
# Y PAN
|
||||
if (mouse_position.y < edge_scrolling_margin or (mouse_position.y > viewport_size.y - edge_scrolling_margin)):
|
||||
pan_direction.y = 1 if (mouse_position.y < viewport_size.y/2) else -1 # detect if we are in the half of the screen or not
|
||||
|
||||
var pan_vector:= Vector2(pan_direction.x,pan_direction.y) * delta * edge_scrolling_speed * get_zoom_factor()
|
||||
|
||||
translate_object_local(Vector3(pan_vector.y,0,pan_vector.x))
|
||||
|
|
Loading…
Reference in a new issue