68 lines
No EOL
2.3 KiB
GDScript
68 lines
No EOL
2.3 KiB
GDScript
extends Spatial
|
|
|
|
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
|
|
|
|
func _process( delta ):
|
|
|
|
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"):
|
|
$dummy/camera_stand.translate( Vector3( 0.0, 0.0,-10.0*delta ) )
|
|
elif Input.is_action_pressed("move_backward"):
|
|
$dummy/camera_stand.translate( Vector3( 0.0, 0.0, 10.0*delta ) )
|
|
if Input.is_action_pressed("move_left"):
|
|
$dummy/camera_stand.translate( Vector3(-10.0*delta, 0.0, 0.0 ) )
|
|
elif Input.is_action_pressed("move_right"):
|
|
$dummy/camera_stand.translate( Vector3( 10.0*delta, 0.0, 0.0 ) )
|
|
|
|
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))
|
|
|
|
|
|
|
|
func _input(event):
|
|
|
|
if event.is_action_pressed( "move_look" ):
|
|
Input.set_mouse_mode( Input.MOUSE_MODE_CAPTURED )
|
|
self._mouse_look = true
|
|
elif event.is_action_released( "move_look" ):
|
|
Input.set_mouse_mode( Input.MOUSE_MODE_VISIBLE )
|
|
self._mouse_look = false
|
|
|
|
if event is InputEventMouseMotion:
|
|
if _mouse_look:
|
|
_mouse_position = event.relative
|
|
|
|
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 )
|
|
|