2019-04-19 10:27:07 +00:00
|
|
|
extends Spatial
|
|
|
|
|
2019-04-27 08:53:11 +00:00
|
|
|
var _mouse_look = false
|
|
|
|
var _mouse_position = Vector2( 0.0, 0.0 )
|
|
|
|
var _yaw = 0.0
|
|
|
|
var _pitch = 0.0
|
|
|
|
var _total_yaw = 0.0
|
|
|
|
var _total_pitch = 0.0
|
|
|
|
var yaw_limit = 360
|
|
|
|
var pitch_limit = 360
|
|
|
|
var sensitivity = 0.5
|
|
|
|
var smoothness = 0.5
|
|
|
|
|
2019-04-19 10:27:07 +00:00
|
|
|
func _process( delta ):
|
2019-04-26 08:36:37 +00:00
|
|
|
|
|
|
|
if Input.is_action_pressed("move_up"):
|
|
|
|
$dummy/camera_stand.translate( Vector3( 0.0, 10.0*delta, 0.0 ) )
|
|
|
|
elif Input.is_action_pressed("move_down"):
|
|
|
|
$dummy/camera_stand.translate( Vector3( 0.0,-10.0*delta, 0.0 ) )
|
|
|
|
elif Input.is_action_pressed("move_forward"):
|
2019-04-19 10:27:07 +00:00
|
|
|
$dummy/camera_stand.translate( Vector3( 0.0, 0.0,-10.0*delta ) )
|
2019-04-26 08:36:37 +00:00
|
|
|
elif Input.is_action_pressed("move_backward"):
|
2019-04-19 10:27:07 +00:00
|
|
|
$dummy/camera_stand.translate( Vector3( 0.0, 0.0, 10.0*delta ) )
|
2019-04-27 08:53:11 +00:00
|
|
|
if Input.is_action_pressed("move_left"):
|
2019-04-25 20:38:32 +00:00
|
|
|
$dummy/camera_stand.translate( Vector3(-10.0*delta, 0.0, 0.0 ) )
|
2019-04-26 08:36:37 +00:00
|
|
|
elif Input.is_action_pressed("move_right"):
|
2019-04-25 20:38:32 +00:00
|
|
|
$dummy/camera_stand.translate( Vector3( 10.0*delta, 0.0, 0.0 ) )
|
2019-04-27 08:53:11 +00:00
|
|
|
|
|
|
|
if _mouse_look:
|
|
|
|
_update_mouselook()
|
|
|
|
|
|
|
|
func _update_mouselook():
|
|
|
|
_mouse_position *= sensitivity
|
|
|
|
_yaw = _yaw * smoothness + _mouse_position.x * (1.0 - smoothness)
|
|
|
|
_pitch = _pitch * smoothness + _mouse_position.y * (1.0 - smoothness)
|
|
|
|
_mouse_position = Vector2(0, 0)
|
|
|
|
|
|
|
|
if yaw_limit < 360:
|
|
|
|
_yaw = clamp(_yaw, -yaw_limit - _total_yaw, yaw_limit - _total_yaw)
|
|
|
|
if pitch_limit < 360:
|
|
|
|
_pitch = clamp(_pitch, -pitch_limit - _total_pitch, pitch_limit - _total_pitch)
|
|
|
|
|
|
|
|
_total_yaw += _yaw
|
|
|
|
_total_pitch += _pitch
|
|
|
|
|
|
|
|
$dummy/camera_stand.rotate_y(deg2rad(-_yaw))
|
|
|
|
$dummy/camera_stand.rotate_object_local(Vector3(1,0,0), deg2rad(-_pitch))
|
|
|
|
|
|
|
|
|
2019-04-25 20:38:32 +00:00
|
|
|
|
|
|
|
func _input(event):
|
|
|
|
|
|
|
|
if event.is_action_pressed( "move_look" ):
|
|
|
|
Input.set_mouse_mode( Input.MOUSE_MODE_CAPTURED )
|
2019-04-27 08:53:11 +00:00
|
|
|
self._mouse_look = true
|
2019-04-25 20:38:32 +00:00
|
|
|
elif event.is_action_released( "move_look" ):
|
|
|
|
Input.set_mouse_mode( Input.MOUSE_MODE_VISIBLE )
|
2019-04-27 08:53:11 +00:00
|
|
|
self._mouse_look = false
|
2019-04-25 20:38:32 +00:00
|
|
|
|
|
|
|
if event is InputEventMouseMotion:
|
2019-04-27 08:53:11 +00:00
|
|
|
if _mouse_look:
|
|
|
|
_mouse_position = event.relative
|
|
|
|
|
2019-04-25 20:48:24 +00:00
|
|
|
if event.is_action_pressed( "move_zoom_in" ):
|
|
|
|
$dummy/camera_stand/camera.set_fov( $dummy/camera_stand/camera.get_fov()-1.0 )
|
|
|
|
elif event.is_action_pressed( "move_zoom_out" ):
|
|
|
|
$dummy/camera_stand/camera.set_fov( $dummy/camera_stand/camera.get_fov()+1.0 )
|
|
|
|
|