added proper touch controls and put terrain in a separate file
This commit is contained in:
parent
3be1d07acd
commit
bdfcc74491
10 changed files with 77 additions and 35 deletions
|
|
@ -2,6 +2,7 @@ extends CharacterBody3D
|
|||
|
||||
@onready var animated_mesh: Node3D = %GobotSkin
|
||||
@onready var camera: Camera3D = %Camera3D
|
||||
@onready var camera_root: Node3D = $CameraRoot
|
||||
|
||||
## State
|
||||
@export var battle_state: Enums.BattleState = Enums.BattleState.NOT_IN_BATTLE
|
||||
|
|
@ -15,6 +16,7 @@ const JUMP_VELOCITY: float = 4.5
|
|||
const ROTATION_SPEED: float = 12.0
|
||||
const CAMERA_ROTATION_SPEED: float = 1.3
|
||||
const MANUAL_CAMERA_ROTATION_SPEED: float = 5.0
|
||||
var camera_smoothing_factor: float = 0.1
|
||||
|
||||
func _ready() -> void:
|
||||
# Set the global reference to the player
|
||||
|
|
@ -24,7 +26,6 @@ func _ready() -> void:
|
|||
# HACK: This should rather be connected from a global SignalManager or SignalBus
|
||||
get_viewport().get_tree().get_root().find_child("JoystickPanel", true, false).connect("on_interact", interact)
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
# If the player is in a battle, handle it via start_battle and then handle_battle
|
||||
if battle_state != Enums.BattleState.NOT_IN_BATTLE:
|
||||
|
|
@ -45,10 +46,6 @@ func _physics_process(delta: float) -> void:
|
|||
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
||||
velocity.y = JUMP_VELOCITY
|
||||
|
||||
# Manual camera rotation
|
||||
var camera_input_dir : Vector2 = Input.get_vector("joystick_right_left", "joystick_right_right", "joystick_right_left", "joystick_right_right")
|
||||
$CameraRoot.rotation.y += camera_input_dir.x * MANUAL_CAMERA_ROTATION_SPEED * delta
|
||||
|
||||
# Get the input direction and handle the movement / deceleration.
|
||||
# As good practice, you should replace UI actions with custom gameplay actions.
|
||||
var input_dir : Vector2 = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://be5bc5gjbo875"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://be5bc5gjbo875"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://be00fdjdehq03" path="res://entities/player/player.gd" id="1_mv2yl"]
|
||||
[ext_resource type="PackedScene" uid="uid://cy36aygvs66pn" path="res://assets/models/gobot/gobot_skin.tscn" id="2_a4t6w"]
|
||||
[ext_resource type="Script" uid="uid://dgjc3dw1gbiyg" path="res://ui/touch_controls.gd" id="2_sglur"]
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_xuba7"]
|
||||
height = 1.7
|
||||
|
|
@ -13,6 +14,10 @@ axis_lock_angular_y = true
|
|||
axis_lock_angular_z = true
|
||||
script = ExtResource("1_mv2yl")
|
||||
|
||||
[node name="TouchControls" type="Node" parent="."]
|
||||
script = ExtResource("2_sglur")
|
||||
metadata/_custom_type_script = ExtResource("2_sglur")
|
||||
|
||||
[node name="GobotSkin" parent="." instance=ExtResource("2_a4t6w")]
|
||||
unique_name_in_owner = true
|
||||
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, 0)
|
||||
|
|
@ -23,10 +28,12 @@ shape = SubResource("CapsuleShape3D_xuba7")
|
|||
|
||||
[node name="CameraRoot" type="Node3D" parent="."]
|
||||
unique_name_in_owner = true
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.2, 0)
|
||||
|
||||
[node name="SpringArm3D" type="SpringArm3D" parent="CameraRoot"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.64528, 2.83335)
|
||||
collision_mask = 14
|
||||
spring_length = 5.0
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="CameraRoot/SpringArm3D"]
|
||||
unique_name_in_owner = true
|
||||
transform = Transform3D(1, 0, 0, 0, 0.965926, 0.258819, 0, -0.258819, 0.965926, 0, 0.0210915, 0.372644)
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0)
|
||||
|
|
|
|||
|
|
@ -64,22 +64,22 @@ theme/custom="res://theme/basic_theme.tres"
|
|||
|
||||
joystick_right_right={
|
||||
"deadzone": 0.0,
|
||||
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-3,"axis":2,"axis_value":1.0,"script":null)
|
||||
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":1.0,"script":null)
|
||||
]
|
||||
}
|
||||
joystick_right_left={
|
||||
"deadzone": 0.0,
|
||||
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-3,"axis":2,"axis_value":-1.0,"script":null)
|
||||
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":-1.0,"script":null)
|
||||
]
|
||||
}
|
||||
joystick_right_up={
|
||||
"deadzone": 0.0,
|
||||
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-3,"axis":3,"axis_value":-1.0,"script":null)
|
||||
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":-1.0,"script":null)
|
||||
]
|
||||
}
|
||||
joystick_right_down={
|
||||
"deadzone": 0.0,
|
||||
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-3,"axis":3,"axis_value":1.0,"script":null)
|
||||
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":1.0,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
|
|
|
|||
27
ui/touch_controls.gd
Normal file
27
ui/touch_controls.gd
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
extends Node
|
||||
class_name TouchControls
|
||||
|
||||
@export var touch_controls_enabled: bool = true
|
||||
@export_range(0.0, 0.01, 0.0001) var touch_sensitivity: float = 0.01
|
||||
|
||||
@export var tilt_limit_high: float = deg_to_rad(75)
|
||||
@export var tilt_limit_low: float = deg_to_rad(20)
|
||||
|
||||
@onready var _camera: Camera3D = %Camera3D
|
||||
@onready var _camera_pivot: Node3D = %CameraRoot
|
||||
|
||||
var target_rotation: Vector2 = Vector2(0, 0)
|
||||
@export_range(0.01, 1.0, 0.01) var smoothing_factor: float = 0.1
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event is InputEventScreenDrag:
|
||||
#_camera_pivot.rotation.x -= event.screen_relative.y * touch_sensitivity
|
||||
target_rotation.x -= event.screen_relative.y * touch_sensitivity
|
||||
target_rotation.y += -event.screen_relative.x * touch_sensitivity
|
||||
|
||||
target_rotation.x = clampf(target_rotation.x, -tilt_limit_high, tilt_limit_low)
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
_camera_pivot.rotation.x = lerp(_camera_pivot.rotation.x, target_rotation.x, smoothing_factor)
|
||||
_camera_pivot.rotation.y = lerp(_camera_pivot.rotation.y, target_rotation.y, smoothing_factor)
|
||||
pass
|
||||
1
ui/touch_controls.gd.uid
Normal file
1
ui/touch_controls.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dgjc3dw1gbiyg
|
||||
2
ui/ui.gd
2
ui/ui.gd
|
|
@ -8,7 +8,7 @@ signal on_game_continued
|
|||
@onready var main_menu: Control = $MainMenu
|
||||
@onready var ingame_controls: Control = $IngameControls
|
||||
@onready var ingame_menu: Control = $IngameMenu
|
||||
@onready var camera_control_area : Control = $CameraControlArea
|
||||
#@onready var camera_control_area : Control = $CameraControlArea
|
||||
@onready var save_ui : Control = $SaveUI
|
||||
@onready var battle_ui : Control = $BattleUI
|
||||
|
||||
|
|
|
|||
12
ui/ui.tscn
12
ui/ui.tscn
|
|
@ -1,7 +1,6 @@
|
|||
[gd_scene load_steps=7 format=3 uid="uid://b5y7pdfe6ougf"]
|
||||
[gd_scene load_steps=6 format=3 uid="uid://b5y7pdfe6ougf"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bhajdnao0awhr" path="res://ui/ui.gd" id="1_fkttd"]
|
||||
[ext_resource type="Script" uid="uid://cp2jtkql0gaci" path="res://ui/ingame_controls/camera_controls.gd" id="1_x56x6"]
|
||||
[ext_resource type="PackedScene" uid="uid://dt00rjsodtady" path="res://ui/main_menu/main_menu.tscn" id="3_tcmm8"]
|
||||
[ext_resource type="PackedScene" uid="uid://1anjhvi173g3" path="res://ui/ingame_controls/ingame_controls.tscn" id="4_likk0"]
|
||||
[ext_resource type="PackedScene" uid="uid://bbvbnrcjatkrb" path="res://ui/ingame_menu/ingame_menu.tscn" id="5_qjqu1"]
|
||||
|
|
@ -10,15 +9,6 @@
|
|||
[node name="UI" type="CanvasLayer"]
|
||||
script = ExtResource("1_fkttd")
|
||||
|
||||
[node name="CameraControlArea" type="Control" parent="."]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_x56x6")
|
||||
|
||||
[node name="SaveUI" type="Control" parent="."]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
[gd_scene load_steps=31 format=3 uid="uid://cavbs8gurvpfh"]
|
||||
[gd_scene load_steps=30 format=3 uid="uid://cavbs8gurvpfh"]
|
||||
|
||||
[ext_resource type="Terrain3DStorage" uid="uid://c4h6ufb0esmas" path="res://worlds/terrain1/terrain1_storage.res" id="1_k1mvv"]
|
||||
[ext_resource type="Terrain3DMaterial" uid="uid://c6ppgrnektc8g" path="res://worlds/terrain1/terrain1_material.tres" id="2_2cdhe"]
|
||||
[ext_resource type="Terrain3DAssets" uid="uid://bh60t03kfpvux" path="res://worlds/terrain1/terrain1_assets.tres" id="3_5hdjg"]
|
||||
[ext_resource type="PackedScene" uid="uid://dvujb1wo0or87" path="res://worlds/terrain1/terrain1_terrain_3d.tscn" id="1_xh2t6"]
|
||||
[ext_resource type="PackedScene" uid="uid://dawpmu4vvv3rs" path="res://entities/monster_spawnpoint/monster_spawnpoint.tscn" id="4_l81pf"]
|
||||
[ext_resource type="Script" uid="uid://b44bktvws5v3s" path="res://entities/monster_spawnpoint/monster_spawnpoint_probability.gd" id="5_6bskj"]
|
||||
[ext_resource type="Resource" uid="uid://0xqaef8uftnv" path="res://resources/monsters/debuggy.tres" id="6_of6wf"]
|
||||
|
|
@ -45,6 +43,8 @@ script = ExtResource("5_6bskj")
|
|||
monster_data = ExtResource("6_of6wf")
|
||||
chance = 100.0
|
||||
|
||||
[sub_resource type="WorldBoundaryShape3D" id="WorldBoundaryShape3D_77mbb"]
|
||||
|
||||
[node name="Terrain1" type="Node3D"]
|
||||
|
||||
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
|
||||
|
|
@ -54,13 +54,10 @@ shadow_enabled = true
|
|||
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
|
||||
environment = SubResource("Environment_tunrb")
|
||||
|
||||
[node name="Terrain3D" type="Terrain3D" parent="."]
|
||||
storage = ExtResource("1_k1mvv")
|
||||
material = ExtResource("2_2cdhe")
|
||||
assets = ExtResource("3_5hdjg")
|
||||
render_cast_shadows = 0
|
||||
collision_layer = 2
|
||||
collision_mask = 9
|
||||
[node name="Terrain3D" parent="." instance=ExtResource("1_xh2t6")]
|
||||
collision_enabled = true
|
||||
collision_mask = 13
|
||||
visible = true
|
||||
|
||||
[node name="Stones" type="Node3D" parent="."]
|
||||
|
||||
|
|
@ -151,3 +148,10 @@ spawnable_monsters = Array[ExtResource("5_6bskj")]([SubResource("Resource_rgf8x"
|
|||
min_level = 2
|
||||
max_level = 5
|
||||
ignore_visibility = true
|
||||
|
||||
[node name="StaticBody3D" type="StaticBody3D" parent="."]
|
||||
collision_layer = 2
|
||||
collision_mask = 13
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D"]
|
||||
shape = SubResource("WorldBoundaryShape3D_77mbb")
|
||||
|
|
|
|||
|
|
@ -39,4 +39,5 @@ _shader_parameters = {
|
|||
"noise_texture": SubResource("NoiseTexture2D_i4bum"),
|
||||
"vertex_normals_distance": 128.0
|
||||
}
|
||||
world_background = 0
|
||||
auto_shader = true
|
||||
|
|
|
|||
15
worlds/terrain1/terrain1_terrain_3d.tscn
Normal file
15
worlds/terrain1/terrain1_terrain_3d.tscn
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://dvujb1wo0or87"]
|
||||
|
||||
[ext_resource type="Terrain3DStorage" uid="uid://c4h6ufb0esmas" path="res://worlds/terrain1/terrain1_storage.res" id="1_2k2pr"]
|
||||
[ext_resource type="Terrain3DMaterial" uid="uid://c6ppgrnektc8g" path="res://worlds/terrain1/terrain1_material.tres" id="2_x3dgu"]
|
||||
[ext_resource type="Terrain3DAssets" uid="uid://bh60t03kfpvux" path="res://worlds/terrain1/terrain1_assets.tres" id="3_1cb50"]
|
||||
|
||||
[node name="Terrain3D" type="Terrain3D"]
|
||||
storage = ExtResource("1_2k2pr")
|
||||
material = ExtResource("2_x3dgu")
|
||||
assets = ExtResource("3_1cb50")
|
||||
render_cast_shadows = 0
|
||||
collision_enabled = false
|
||||
collision_layer = 2
|
||||
collision_mask = 9
|
||||
visible = false
|
||||
Loading…
Add table
Add a link
Reference in a new issue