Merge branch 'master' of ssh://git.khaganat.net:3543/khaganat/mmorpg_khanat/khanat-assets---3d-godot-client

This commit is contained in:
yannk 2019-04-27 13:53:05 +02:00
commit 21c5d3369d
9 changed files with 76 additions and 15 deletions

View file

@ -5,4 +5,3 @@
[resource] [resource]
background_mode = 2 background_mode = 2
background_sky = SubResource( 1 ) background_sky = SubResource( 1 )

View file

@ -1,30 +1,78 @@
extends Spatial 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 _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
func _process( delta ): func _process( delta ):
if Input.is_action_pressed("move_forward"): if Input.is_action_pressed("move_up"):
$dummy/camera_stand.translate( Vector3( 0.0, 0.0,-10.0*delta ) ) $dummy/camera_stand.translate( Vector3( 0.0, self._current_camera_speed*delta, 0.0 ) )
if Input.is_action_pressed("move_backward"): elif Input.is_action_pressed("move_down"):
$dummy/camera_stand.translate( Vector3( 0.0, 0.0, 10.0*delta ) ) $dummy/camera_stand.translate( Vector3( 0.0,-self._current_camera_speed*delta, 0.0 ) )
elif Input.is_action_pressed("move_forward"):
$dummy/camera_stand.translate( Vector3( 0.0, 0.0,-self._current_camera_speed*delta ) )
elif Input.is_action_pressed("move_backward"):
$dummy/camera_stand.translate( Vector3( 0.0, 0.0, self._current_camera_speed*delta ) )
if Input.is_action_pressed("move_left"): if Input.is_action_pressed("move_left"):
$dummy/camera_stand.translate( Vector3(-10.0*delta, 0.0, 0.0 ) ) $dummy/camera_stand.translate( Vector3(-self._current_camera_speed*delta, 0.0, 0.0 ) )
if Input.is_action_pressed("move_right"): elif Input.is_action_pressed("move_right"):
$dummy/camera_stand.translate( Vector3( 10.0*delta, 0.0, 0.0 ) ) $dummy/camera_stand.translate( Vector3( self._current_camera_speed*delta, 0.0, 0.0 ) )
if _mouse_look:
_update_mouselook()
func _update_mouselook():
_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)
_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): func _input(event):
if event.is_action_pressed( "move_look" ): if event.is_action_pressed( "move_look" ):
Input.set_mouse_mode( Input.MOUSE_MODE_CAPTURED ) Input.set_mouse_mode( Input.MOUSE_MODE_CAPTURED )
self._mouse_look = true
elif event.is_action_released( "move_look" ): elif event.is_action_released( "move_look" ):
Input.set_mouse_mode( Input.MOUSE_MODE_VISIBLE ) Input.set_mouse_mode( Input.MOUSE_MODE_VISIBLE )
self._mouse_look = false
if event is InputEventMouseMotion: if event is InputEventMouseMotion:
if Input.is_action_pressed( "move_look" ): if _mouse_look:
$dummy/camera_stand/camera.rotate_x( -event.relative.y * 0.01 ) _mouse_position = event.relative
$dummy/camera_stand.rotate_y( -event.relative.x * 0.01 )
if event.is_action_pressed( "move_zoom_in" ): if event.is_action_pressed( "move_zoom_in" ):
$dummy/camera_stand/camera.set_fov( $dummy/camera_stand/camera.get_fov()-1.0 ) $dummy/camera_stand/camera.set_fov( $dummy/camera_stand/camera.get_fov()-1.0 )
elif event.is_action_pressed( "move_zoom_out" ): elif event.is_action_pressed( "move_zoom_out" ):
$dummy/camera_stand/camera.set_fov( $dummy/camera_stand/camera.get_fov()+1.0 ) $dummy/camera_stand/camera.set_fov( $dummy/camera_stand/camera.get_fov()+1.0 )
if event.is_action_pressed( "move_speed" ):
self._current_camera_speed = self.camera_speed + self.camera_accel
elif event.is_action_released( "move_speed" ):
self._current_camera_speed = self.camera_speed

View file

@ -71,4 +71,3 @@ shadow_enabled = true
[node name="gi_probe" type="GIProbe" parent="light_system"] [node name="gi_probe" type="GIProbe" parent="light_system"]
extents = Vector3( 63.192, 10, 76.3229 ) extents = Vector3( 63.192, 10, 76.3229 )
data = SubResource( 5 ) data = SubResource( 5 )

View file

@ -56,6 +56,21 @@ move_zoom_out={
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":5,"pressed":false,"doubleclick":false,"script":null) "events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":5,"pressed":false,"doubleclick":false,"script":null)
] ]
} }
move_up={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":true,"meta":false,"command":true,"pressed":false,"scancode":16777232,"unicode":0,"echo":false,"script":null)
]
}
move_down={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":true,"meta":false,"command":true,"pressed":false,"scancode":16777234,"unicode":0,"echo":false,"script":null)
]
}
move_speed={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777237,"unicode":0,"echo":false,"script":null)
]
}
[node] [node]