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:
osquallo 2019-04-27 11:17:41 +02:00
parent 854c6eeb43
commit 13da264b1e
3 changed files with 37 additions and 22 deletions

View file

@ -6,33 +6,41 @@ 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
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 ):
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"):
$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"):
$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"):
$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"):
$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"):
$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 *= sensitivity
_yaw = _yaw * smoothness + _mouse_position.x * (1.0 - smoothness)
_pitch = _pitch * smoothness + _mouse_position.y * (1.0 - smoothness)
_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:
@ -46,8 +54,6 @@ func _update_mouselook():
$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" ):
@ -65,4 +71,8 @@ func _input(event):
$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 )
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

@ -1,11 +1,11 @@
[gd_scene load_steps=12 format=2]
[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://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/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]
@ -39,7 +39,7 @@ script = ExtResource( 1 )
[node name="world_environment" type="WorldEnvironment" parent="."]
environment = SubResource( 2 )
[node name="dummy" parent="." instance=ExtResource( 4 )]
[node name="dummy" parent="." instance=ExtResource( 2 )]
[node name="terrain" type="Spatial" parent="."]
@ -49,13 +49,13 @@ mesh = SubResource( 4 )
[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 )
[node name="container" parent="props" instance=ExtResource( 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="."]

View file

@ -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)
]
}
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]