camera rotation
This commit is contained in:
parent
b20f3b5124
commit
ccd3ef577c
3 changed files with 60 additions and 15 deletions
|
|
@ -1,10 +1,11 @@
|
||||||
[gd_scene load_steps=7 format=3 uid="uid://cswuap81n7t3f"]
|
[gd_scene load_steps=8 format=3 uid="uid://cswuap81n7t3f"]
|
||||||
|
|
||||||
[ext_resource type="Texture2D" uid="uid://b6ylra30qxf30" path="res://assets/logo/logo.png" id="1_fpt28"]
|
[ext_resource type="Texture2D" uid="uid://b6ylra30qxf30" path="res://assets/logo/logo.png" id="1_fpt28"]
|
||||||
[ext_resource type="PackedScene" uid="uid://p8agd0dfam0p" path="res://scenes/debug_level.tscn" id="1_j851n"]
|
[ext_resource type="PackedScene" uid="uid://p8agd0dfam0p" path="res://scenes/debug_level.tscn" id="1_j851n"]
|
||||||
[ext_resource type="FontFile" uid="uid://dmc6dygxrekja" path="res://assets/fonts/BreatheFireIii-PKLOB.ttf" id="2_vjast"]
|
[ext_resource type="FontFile" uid="uid://dmc6dygxrekja" path="res://assets/fonts/BreatheFireIii-PKLOB.ttf" id="2_vjast"]
|
||||||
[ext_resource type="Script" path="res://scripts/joystick.gd" id="4_6b5cb"]
|
[ext_resource type="Script" path="res://scripts/joystick.gd" id="4_6b5cb"]
|
||||||
[ext_resource type="Texture2D" uid="uid://8anyvhkcy4ng" path="res://assets/textures/Xbox Series/Vector/xbox_button_a.svg" id="5_pwhwh"]
|
[ext_resource type="Texture2D" uid="uid://8anyvhkcy4ng" path="res://assets/textures/Xbox Series/Vector/xbox_button_a.svg" id="5_pwhwh"]
|
||||||
|
[ext_resource type="Script" path="res://scripts/camera_controls.gd" id="6_u5aqx"]
|
||||||
|
|
||||||
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_7t5ln"]
|
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_7t5ln"]
|
||||||
|
|
||||||
|
|
@ -81,6 +82,15 @@ text = "Exit"
|
||||||
|
|
||||||
[node name="ControlsLayer" type="CanvasLayer" parent="."]
|
[node name="ControlsLayer" type="CanvasLayer" parent="."]
|
||||||
|
|
||||||
|
[node name="CameraControls" type="Control" parent="ControlsLayer"]
|
||||||
|
layout_mode = 3
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
script = ExtResource("6_u5aqx")
|
||||||
|
|
||||||
[node name="VBoxContainer2" type="VBoxContainer" parent="ControlsLayer"]
|
[node name="VBoxContainer2" type="VBoxContainer" parent="ControlsLayer"]
|
||||||
anchors_preset = 12
|
anchors_preset = 12
|
||||||
anchor_top = 1.0
|
anchor_top = 1.0
|
||||||
|
|
@ -88,9 +98,11 @@ anchor_right = 1.0
|
||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 0
|
grow_vertical = 0
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
size_flags_vertical = 3
|
||||||
|
|
||||||
[node name="Panel" type="Panel" parent="ControlsLayer/VBoxContainer2"]
|
[node name="Panel" type="Panel" parent="ControlsLayer/VBoxContainer2"]
|
||||||
custom_minimum_size = Vector2(200, 200)
|
custom_minimum_size = Vector2(300, 300)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 0
|
size_flags_horizontal = 0
|
||||||
theme_override_styles/panel = SubResource("StyleBoxEmpty_7t5ln")
|
theme_override_styles/panel = SubResource("StyleBoxEmpty_7t5ln")
|
||||||
|
|
@ -103,5 +115,6 @@ offset_right = 40.0
|
||||||
offset_bottom = 40.0
|
offset_bottom = 40.0
|
||||||
texture = ExtResource("5_pwhwh")
|
texture = ExtResource("5_pwhwh")
|
||||||
|
|
||||||
|
[connection signal="gui_input" from="ControlsLayer/CameraControls" to="ControlsLayer/CameraControls" method="_on_gui_input"]
|
||||||
[connection signal="gui_input" from="ControlsLayer/VBoxContainer2/Panel" to="ControlsLayer/VBoxContainer2/Panel" method="_on_gui_input"]
|
[connection signal="gui_input" from="ControlsLayer/VBoxContainer2/Panel" to="ControlsLayer/VBoxContainer2/Panel" method="_on_gui_input"]
|
||||||
[connection signal="resized" from="ControlsLayer/VBoxContainer2/Panel" to="ControlsLayer/VBoxContainer2/Panel" method="_on_resized"]
|
[connection signal="resized" from="ControlsLayer/VBoxContainer2/Panel" to="ControlsLayer/VBoxContainer2/Panel" method="_on_resized"]
|
||||||
|
|
|
||||||
43
scripts/camera_controls.gd
Normal file
43
scripts/camera_controls.gd
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
extends Control
|
||||||
|
|
||||||
|
var touch_start: Vector2 = Vector2(0, 0)
|
||||||
|
var pressed: bool = false
|
||||||
|
var previous_position: Vector2 = Vector2(0,0)
|
||||||
|
var touch_delta: Vector2 = Vector2(0, 0)
|
||||||
|
var current_delta: Vector2 = Vector2()
|
||||||
|
var dampening_factor: float = 0.1 # Lower values = more dampening (0-1 range)
|
||||||
|
|
||||||
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
|
func _process(delta: float) -> void:
|
||||||
|
current_delta = lerp(current_delta, Vector2(0, 0), dampening_factor)
|
||||||
|
print(current_delta)
|
||||||
|
simulate_joystick_motion(JOY_AXIS_RIGHT_X, -current_delta.x * 0.1, 0)
|
||||||
|
|
||||||
|
func _on_gui_input(event: InputEvent) -> void:
|
||||||
|
if event is not InputEventScreenTouch and event is not InputEventScreenDrag:
|
||||||
|
return
|
||||||
|
|
||||||
|
if event is InputEventScreenTouch and pressed == false and event.is_pressed() == true:
|
||||||
|
pressed = true
|
||||||
|
touch_start = event.position
|
||||||
|
#print("touch start")
|
||||||
|
|
||||||
|
if event is InputEventScreenTouch and pressed == true and event.is_pressed() == false:
|
||||||
|
pressed = false
|
||||||
|
#simulate_joystick_motion(JOY_AXIS_RIGHT_X, 0, 0)
|
||||||
|
#print("touch end")
|
||||||
|
|
||||||
|
if pressed and event is InputEventScreenDrag:
|
||||||
|
touch_delta = event.position - previous_position
|
||||||
|
|
||||||
|
current_delta = touch_delta #lerp(current_delta, touch_delta, 1.0 - dampening_factor)
|
||||||
|
|
||||||
|
previous_position = event.position
|
||||||
|
|
||||||
|
func simulate_joystick_motion(axis: int, value: float, device_id: int = 0) -> void:
|
||||||
|
var joystick_event = InputEventJoypadMotion.new()
|
||||||
|
joystick_event.device = device_id
|
||||||
|
joystick_event.axis = axis # Axis index (e.g., 0 for X-axis, 1 for Y-axis)
|
||||||
|
joystick_event.axis_value = value # Value of the axis, typically between -1 and 1
|
||||||
|
|
||||||
|
Input.parse_input_event(joystick_event) # Process the event
|
||||||
|
|
@ -18,25 +18,14 @@ var rotation_delta: Vector2 = Vector2(0, 0)
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
thumbstick.custom_minimum_size = Vector2(size.x, size.x) * thumbstick_size_factor
|
thumbstick.custom_minimum_size = Vector2(size.x, size.x) * thumbstick_size_factor
|
||||||
thumbstick.position = middle - thumbstick.size / 2.0
|
thumbstick.position = middle - thumbstick.size / 2.0
|
||||||
print(thumbstick)
|
|
||||||
|
|
||||||
func _unhandled_input(event: InputEvent) -> void:
|
|
||||||
if event is not InputEventScreenDrag:
|
|
||||||
return
|
|
||||||
|
|
||||||
if event is InputEventScreenDrag:
|
|
||||||
var touch_position = event.position
|
|
||||||
rotation_delta = get_viewport_rect().size / 2 - touch_position
|
|
||||||
simulate_joystick_motion(JOY_AXIS_RIGHT_X, -rotation_delta.x * 0.4, 0)
|
|
||||||
print(rotation_delta)
|
|
||||||
|
|
||||||
func _on_gui_input(event: InputEvent) -> void:
|
func _on_gui_input(event: InputEvent) -> void:
|
||||||
if event is not InputEventScreenTouch and event is not InputEventScreenDrag:
|
if event is not InputEventScreenTouch and event is not InputEventScreenDrag:
|
||||||
return
|
return
|
||||||
|
|
||||||
if event.is_pressed() == false:
|
if event.is_pressed() == false:
|
||||||
simulate_joystick_motion(0, Vector2.ZERO.x)
|
simulate_joystick_motion(JOY_AXIS_LEFT_X, Vector2.ZERO.x)
|
||||||
simulate_joystick_motion(1, Vector2.ZERO.y)
|
simulate_joystick_motion(JOY_AXIS_LEFT_Y, Vector2.ZERO.y)
|
||||||
thumbstick.position = middle - thumbstick.size / 2.0
|
thumbstick.position = middle - thumbstick.size / 2.0
|
||||||
thumbstick.texture = talk_a_texture
|
thumbstick.texture = talk_a_texture
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue