Previewer: reglage de la vitesse et ajout de la possibilite d'accelerer avec shift, export de variables pour pouvoir les modifier sans toucher au code.
This commit is contained in:
parent
854c6eeb43
commit
13da264b1e
3 changed files with 37 additions and 22 deletions
|
@ -6,33 +6,41 @@ var _yaw = 0.0
|
||||||
var _pitch = 0.0
|
var _pitch = 0.0
|
||||||
var _total_yaw = 0.0
|
var _total_yaw = 0.0
|
||||||
var _total_pitch = 0.0
|
var _total_pitch = 0.0
|
||||||
var yaw_limit = 360
|
var _current_camera_speed = 1.0
|
||||||
var pitch_limit = 360
|
|
||||||
var sensitivity = 0.5
|
export(int) var yaw_limit = 360
|
||||||
var smoothness = 0.5
|
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_up"):
|
if Input.is_action_pressed("move_up"):
|
||||||
$dummy/camera_stand.translate( Vector3( 0.0, 10.0*delta, 0.0 ) )
|
$dummy/camera_stand.translate( Vector3( 0.0, self._current_camera_speed*delta, 0.0 ) )
|
||||||
elif Input.is_action_pressed("move_down"):
|
elif Input.is_action_pressed("move_down"):
|
||||||
$dummy/camera_stand.translate( Vector3( 0.0,-10.0*delta, 0.0 ) )
|
$dummy/camera_stand.translate( Vector3( 0.0,-self._current_camera_speed*delta, 0.0 ) )
|
||||||
elif Input.is_action_pressed("move_forward"):
|
elif Input.is_action_pressed("move_forward"):
|
||||||
$dummy/camera_stand.translate( Vector3( 0.0, 0.0,-10.0*delta ) )
|
$dummy/camera_stand.translate( Vector3( 0.0, 0.0,-self._current_camera_speed*delta ) )
|
||||||
elif Input.is_action_pressed("move_backward"):
|
elif Input.is_action_pressed("move_backward"):
|
||||||
$dummy/camera_stand.translate( Vector3( 0.0, 0.0, 10.0*delta ) )
|
$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 ) )
|
||||||
elif 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:
|
if _mouse_look:
|
||||||
_update_mouselook()
|
_update_mouselook()
|
||||||
|
|
||||||
func _update_mouselook():
|
func _update_mouselook():
|
||||||
_mouse_position *= sensitivity
|
_mouse_position *= self.camera_sensitivity
|
||||||
_yaw = _yaw * smoothness + _mouse_position.x * (1.0 - smoothness)
|
_yaw = _yaw * self.camera_smoothness + _mouse_position.x * (1.0 - self.camera_smoothness)
|
||||||
_pitch = _pitch * smoothness + _mouse_position.y * (1.0 - smoothness)
|
_pitch = _pitch * self.camera_smoothness + _mouse_position.y * (1.0 - self.camera_smoothness)
|
||||||
_mouse_position = Vector2(0, 0)
|
_mouse_position = Vector2(0, 0)
|
||||||
|
|
||||||
if yaw_limit < 360:
|
if yaw_limit < 360:
|
||||||
|
@ -46,8 +54,6 @@ func _update_mouselook():
|
||||||
$dummy/camera_stand.rotate_y(deg2rad(-_yaw))
|
$dummy/camera_stand.rotate_y(deg2rad(-_yaw))
|
||||||
$dummy/camera_stand.rotate_object_local(Vector3(1,0,0), deg2rad(-_pitch))
|
$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" ):
|
||||||
|
@ -66,3 +72,7 @@ func _input(event):
|
||||||
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
|
|
@ -1,11 +1,11 @@
|
||||||
[gd_scene load_steps=12 format=2]
|
[gd_scene load_steps=12 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://previewer/previewer.gd" type="Script" id=1]
|
[ext_resource path="res://previewer/previewer.gd" type="Script" id=1]
|
||||||
[ext_resource path="res://meshes/props/reference_box/reference_box.tscn" type="PackedScene" id=2]
|
[ext_resource path="res://previewer/dummy/dummy.tscn" type="PackedScene" id=2]
|
||||||
[ext_resource path="res://materials/tilables/textures/base_UV_check_big.png" type="Texture" id=3]
|
[ext_resource path="res://materials/tilables/textures/base_UV_check_big.png" type="Texture" id=3]
|
||||||
[ext_resource path="res://previewer/dummy/dummy.tscn" type="PackedScene" id=4]
|
[ext_resource path="res://meshes/props/pendo_teddy/pendo_teddy.tscn" type="PackedScene" id=4]
|
||||||
[ext_resource path="res://meshes/props/travel_box/container.tscn" type="PackedScene" id=5]
|
[ext_resource path="res://meshes/props/travel_box/container.tscn" type="PackedScene" id=5]
|
||||||
[ext_resource path="res://meshes/props/pendo_teddy/pendo_teddy.tscn" type="PackedScene" id=6]
|
[ext_resource path="res://meshes/props/reference_box/reference_box.tscn" type="PackedScene" id=6]
|
||||||
|
|
||||||
[sub_resource type="ProceduralSky" id=1]
|
[sub_resource type="ProceduralSky" id=1]
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ script = ExtResource( 1 )
|
||||||
[node name="world_environment" type="WorldEnvironment" parent="."]
|
[node name="world_environment" type="WorldEnvironment" parent="."]
|
||||||
environment = SubResource( 2 )
|
environment = SubResource( 2 )
|
||||||
|
|
||||||
[node name="dummy" parent="." instance=ExtResource( 4 )]
|
[node name="dummy" parent="." instance=ExtResource( 2 )]
|
||||||
|
|
||||||
[node name="terrain" type="Spatial" parent="."]
|
[node name="terrain" type="Spatial" parent="."]
|
||||||
|
|
||||||
|
@ -49,13 +49,13 @@ mesh = SubResource( 4 )
|
||||||
|
|
||||||
[node name="props" type="Spatial" parent="."]
|
[node name="props" type="Spatial" parent="."]
|
||||||
|
|
||||||
[node name="pendo_teddy" parent="props" instance=ExtResource( 6 )]
|
[node name="pendo_teddy" parent="props" instance=ExtResource( 4 )]
|
||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -3 )
|
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -3 )
|
||||||
|
|
||||||
[node name="container" parent="props" instance=ExtResource( 5 )]
|
[node name="container" parent="props" instance=ExtResource( 5 )]
|
||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -5 )
|
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -5 )
|
||||||
|
|
||||||
[node name="reference_box" parent="props" instance=ExtResource( 2 )]
|
[node name="reference_box" parent="props" instance=ExtResource( 6 )]
|
||||||
|
|
||||||
[node name="light_system" type="Spatial" parent="."]
|
[node name="light_system" type="Spatial" parent="."]
|
||||||
|
|
||||||
|
|
|
@ -66,6 +66,11 @@ move_down={
|
||||||
"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)
|
"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]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue