added proper touch controls and put terrain in a separate file

This commit is contained in:
Luca 2024-11-22 19:10:59 +01:00
parent 3be1d07acd
commit bdfcc74491
10 changed files with 77 additions and 35 deletions

View file

@ -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")

View file

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