amelioration de la camera libre(clic droit) qui permet desormais de se deplacer dans tout les direction pas juste de regarder.
This commit is contained in:
parent
a0c4e92ff8
commit
854c6eeb43
2 changed files with 45 additions and 11 deletions
|
@ -1,5 +1,16 @@
|
|||
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"):
|
||||
|
@ -10,23 +21,46 @@ func _process( delta ):
|
|||
$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 ) )
|
||||
elif 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 ) )
|
||||
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 Input.is_action_pressed( "move_look" ):
|
||||
$dummy/camera_stand/camera.rotate_x( -event.relative.y * 0.01 )
|
||||
$dummy/camera_stand.rotate_y( -event.relative.x * 0.01 )
|
||||
|
||||
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" ):
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
[gd_scene load_steps=12 format=2]
|
||||
|
||||
[ext_resource path="res://previewer/previewer.gd" type="Script" id=1]
|
||||
[ext_resource path="res://previewer/dummy/dummy.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://meshes/props/reference_box/reference_box.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://meshes/props/travel_box/container.tscn" type="PackedScene" id=4]
|
||||
[ext_resource path="res://meshes/props/reference_box/reference_box.tscn" type="PackedScene" id=5]
|
||||
[ext_resource path="res://previewer/dummy/dummy.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]
|
||||
|
||||
[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( 2 )]
|
||||
[node name="dummy" parent="." instance=ExtResource( 4 )]
|
||||
|
||||
[node name="terrain" type="Spatial" parent="."]
|
||||
|
||||
|
@ -52,10 +52,10 @@ mesh = SubResource( 4 )
|
|||
[node name="pendo_teddy" parent="props" instance=ExtResource( 6 )]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -3 )
|
||||
|
||||
[node name="container" parent="props" instance=ExtResource( 4 )]
|
||||
[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( 5 )]
|
||||
[node name="reference_box" parent="props" instance=ExtResource( 2 )]
|
||||
|
||||
[node name="light_system" type="Spatial" parent="."]
|
||||
|
||||
|
|
Loading…
Reference in a new issue