diff --git a/player.gd b/player.gd index 6d64f9f..bcc1766 100644 --- a/player.gd +++ b/player.gd @@ -1,13 +1,15 @@ extends CharacterBody3D +@onready var camera: Camera3D = $Camera3D const SPEED = 5.0 const JUMP_VELOCITY = 4.5 -const MOUSE_SENSITIVITY = 0.01 +const MOUSE_SENSITIVITY = 0.005 + func _ready() -> void: - Input.mouse_mode = Input.MOUSE_MODE_CONFINED_HIDDEN + Input.mouse_mode = Input.MOUSE_MODE_CAPTURED func _process(delta: float) -> void: if Input.is_action_just_pressed("ui_cancel"): @@ -15,7 +17,9 @@ func _process(delta: float) -> void: func _unhandled_input(event: InputEvent) -> void: if event is InputEventMouseMotion: - rotate_y(-event.relative.x * MOUSE_SENSITIVITY) + rotate_y(-event.screen_relative.x * MOUSE_SENSITIVITY) + camera.rotate_x(-event.screen_relative.y * MOUSE_SENSITIVITY) + camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-80), deg_to_rad(80)) func _physics_process(delta: float) -> void: # Add the gravity. @@ -25,16 +29,18 @@ func _physics_process(delta: float) -> void: # Handle jump. if Input.is_action_just_pressed("ui_accept") and is_on_floor(): velocity.y = JUMP_VELOCITY + + + var right:Vector3 = (global_transform.basis.x * Vector3(1, 0, 1)).normalized() + var forward:Vector3 = (global_transform.basis.z * Vector3(1, 0, 1)).normalized() - # Get the input direction and handle the movement/deceleration. - # As good practice, you should replace UI actions with custom gameplay actions. - var input_dir := Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down") - var direction := (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized() - if direction: - velocity.x = direction.x * SPEED - velocity.z = direction.z * SPEED - else: - velocity.x = move_toward(velocity.x, 0, SPEED) - velocity.z = move_toward(velocity.z, 0, SPEED) + if Input.is_key_pressed(KEY_LEFT) or Input.is_key_pressed(KEY_A): + global_translate(-right * SPEED * delta) + if Input.is_key_pressed(KEY_RIGHT) or Input.is_key_pressed(KEY_D): + global_translate(right * SPEED * delta) + if Input.is_key_pressed(KEY_UP) or Input.is_key_pressed(KEY_W): + global_translate(-forward * SPEED * delta) + if Input.is_key_pressed(KEY_DOWN) or Input.is_key_pressed(KEY_S): + global_translate(forward * SPEED * delta) move_and_slide() diff --git a/project.godot b/project.godot index 331595f..8208087 100644 --- a/project.godot +++ b/project.godot @@ -11,5 +11,29 @@ config_version=5 [application] config/name="DP Konzultace" +run/main_scene="uid://dpatwnepecl8r" config/features=PackedStringArray("4.4", "Forward Plus") config/icon="res://icon.svg" + +[input] + +move_left={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null) +] +} +move_right={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null) +] +} +move_forward={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null) +] +} +move_back={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null) +] +}