camera: added smooth camera zooming
This commit is contained in:
parent
cf14e5d398
commit
fced905bae
1 changed files with 11 additions and 4 deletions
|
|
@ -7,8 +7,10 @@ var locked_mouse_positon = Vector2(0,0)
|
||||||
var mouse_locked = false
|
var mouse_locked = false
|
||||||
var mouse_x_velocity = 0
|
var mouse_x_velocity = 0
|
||||||
var mouse_y_velocity = 0
|
var mouse_y_velocity = 0
|
||||||
|
|
||||||
var zoom_min = 4
|
var zoom_min = 4
|
||||||
var zoom_max = 100
|
var zoom_max = 80
|
||||||
|
var zoom_speed = 20
|
||||||
var current_zoom = 8
|
var current_zoom = 8
|
||||||
|
|
||||||
func reset():
|
func reset():
|
||||||
|
|
@ -27,9 +29,9 @@ func _input(event):
|
||||||
mouse_x_velocity = event.relative.x
|
mouse_x_velocity = event.relative.x
|
||||||
mouse_y_velocity = event.relative.y
|
mouse_y_velocity = event.relative.y
|
||||||
elif event.is_action_pressed("zoom_out"):
|
elif event.is_action_pressed("zoom_out"):
|
||||||
current_zoom += 5
|
current_zoom += 1
|
||||||
elif event.is_action_pressed("zoom_in"):
|
elif event.is_action_pressed("zoom_in"):
|
||||||
current_zoom -= 5
|
current_zoom -= 1
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
# rotate outer gimbal around y axis
|
# rotate outer gimbal around y axis
|
||||||
|
|
@ -65,4 +67,9 @@ func _process(delta):
|
||||||
reset()
|
reset()
|
||||||
|
|
||||||
current_zoom = clamp(current_zoom, zoom_min, zoom_max)
|
current_zoom = clamp(current_zoom, zoom_min, zoom_max)
|
||||||
$InnerGimbal/Camera3D.position = Vector3($InnerGimbal/Camera3D.position.x, current_zoom, current_zoom)
|
|
||||||
|
var pos = Vector3($InnerGimbal/Camera3D.position)
|
||||||
|
pos.y = lerp(pos.y, float(current_zoom), zoom_speed*delta)
|
||||||
|
pos.z = lerp(pos.z, float(current_zoom), zoom_speed*delta)
|
||||||
|
|
||||||
|
$InnerGimbal/Camera3D.position = pos
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue