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
|
2019-04-27 09:17:41 +00:00
|
|
|
var _current_camera_speed = 1.0
|
|
|
|
|
|
|
|
export(int) var yaw_limit = 360
|
|
|
|
export(int) var pitch_limit = 360
|
|
|
|
export(float) var camera_sensitivity = 0.5
|
|
|
|
export(float) var camera_smoothness = 0.5
|
|
|
|
export(float) var camera_speed = 1.0
|
|
|
|
export(float) var camera_accel = 10.0
|
|
|
|
|
|
|
|
func _ready():
|
|
|
|
self._current_camera_speed = self.camera_speed
|
2019-09-30 16:24:24 +00:00
|
|
|
|
|
|
|
$settings.show()
|
2019-04-27 08:53:11 +00:00
|
|
|
|
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"):
|
2019-04-27 09:17:41 +00:00
|
|
|
$dummy/camera_stand.translate( Vector3( 0.0, self._current_camera_speed*delta, 0.0 ) )
|
2019-04-26 08:36:37 +00:00
|
|
|
elif Input.is_action_pressed("move_down"):
|
2019-04-27 09:17:41 +00:00
|
|
|
$dummy/camera_stand.translate( Vector3( 0.0,-self._current_camera_speed*delta, 0.0 ) )
|
2019-04-26 08:36:37 +00:00
|
|
|
elif Input.is_action_pressed("move_forward"):
|
2019-04-27 09:17:41 +00:00
|
|
|
$dummy/camera_stand.translate( Vector3( 0.0, 0.0,-self._current_camera_speed*delta ) )
|
2019-04-26 08:36:37 +00:00
|
|
|
elif Input.is_action_pressed("move_backward"):
|
2019-04-27 09:17:41 +00:00
|
|
|
$dummy/camera_stand.translate( Vector3( 0.0, 0.0, self._current_camera_speed*delta ) )
|
2019-04-27 08:53:11 +00:00
|
|
|
if Input.is_action_pressed("move_left"):
|
2019-04-27 09:17:41 +00:00
|
|
|
$dummy/camera_stand.translate( Vector3(-self._current_camera_speed*delta, 0.0, 0.0 ) )
|
2019-04-26 08:36:37 +00:00
|
|
|
elif Input.is_action_pressed("move_right"):
|
2019-04-27 09:17:41 +00:00
|
|
|
$dummy/camera_stand.translate( Vector3( self._current_camera_speed*delta, 0.0, 0.0 ) )
|
|
|
|
|
2019-04-27 08:53:11 +00:00
|
|
|
|
|
|
|
if _mouse_look:
|
|
|
|
_update_mouselook()
|
|
|
|
|
|
|
|
func _update_mouselook():
|
2019-04-27 09:17:41 +00:00
|
|
|
_mouse_position *= self.camera_sensitivity
|
|
|
|
_yaw = _yaw * self.camera_smoothness + _mouse_position.x * (1.0 - self.camera_smoothness)
|
|
|
|
_pitch = _pitch * self.camera_smoothness + _mouse_position.y * (1.0 - self.camera_smoothness)
|
2019-04-27 08:53:11 +00:00
|
|
|
_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 )
|
2019-04-27 09:17:41 +00:00
|
|
|
|
|
|
|
if event.is_action_pressed( "move_speed" ):
|
|
|
|
self._current_camera_speed = self.camera_speed + self.camera_accel
|
|
|
|
elif event.is_action_released( "move_speed" ):
|
2019-09-30 16:24:24 +00:00
|
|
|
self._current_camera_speed = self.camera_speed
|
|
|
|
|
|
|
|
if event.is_action_pressed( "ui_settings_window" ):
|
|
|
|
$settings.visible = !$settings.visible
|