Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add touch screen support for 3d/platformer #1128

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions 3d/platformer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Renderer: Forward+

Check out this demo on the asset library: https://godotengine.org/asset-library/asset/2748

This project uses Virtual joystick add-on by [`Marco F`](https://github.com/MarcoFazioRandom) for touch screen input.
check it out: https://godotengine.org/asset-library/asset/1787

## Screenshots

![Screenshot](screenshots/platformer.webp)
2 changes: 1 addition & 1 deletion 3d/platformer/coin/coin.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,10 @@ mesh = SubResource("QuadMesh_kqa4x")
surface_material_override/0 = SubResource("StandardMaterial3D_7q0mq")

[node name="Animation" type="AnimationPlayer" parent="."]
autoplay = "spin"
libraries = {
"": SubResource("AnimationLibrary_7v453")
}
autoplay = "spin"

[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00894194, 0.575859, 0.0193955)
Expand Down
12 changes: 6 additions & 6 deletions 3d/platformer/enemy/enemy.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,8 @@ axis_lock_angular_y = true
axis_lock_angular_z = true
physics_material_override = SubResource("1")
custom_integrator = true
max_contacts_reported = 5
contact_monitor = true
max_contacts_reported = 5
script = ExtResource("1")

[node name="Enemy" parent="." instance=ExtResource("2_qf8n3")]
Expand All @@ -448,13 +448,13 @@ bones/1/position = Vector3(-5.04871e-28, 0.661877, 0)
bones/1/rotation = Quaternion(0.707107, -2.48537e-07, -1.95408e-07, 0.707107)
bones/2/position = Vector3(-3.87449e-08, 0.475726, -0.0617121)
bones/3/position = Vector3(0.913587, 0.661877, 0.631826)
bones/3/rotation = Quaternion(1, 0, 7.54979e-08, -1.05879e-22)
bones/3/rotation = Quaternion(1, -2.49197e-38, 7.54979e-08, -1.05879e-22)
bones/5/position = Vector3(-0.913587, 0.661877, 0.631826)
bones/5/rotation = Quaternion(1, 0, 7.54979e-08, -1.05879e-22)
bones/5/rotation = Quaternion(1, -2.49197e-38, 7.54979e-08, -1.05879e-22)
bones/7/position = Vector3(1.05436, 0.661877, -0.654576)
bones/7/rotation = Quaternion(1, 0, 7.54979e-08, -1.05879e-22)
bones/7/rotation = Quaternion(1, -2.49197e-38, 7.54979e-08, -1.05879e-22)
bones/9/position = Vector3(-1.05436, 0.661877, -0.654576)
bones/9/rotation = Quaternion(1, 0, 7.54979e-08, -1.05879e-22)
bones/9/rotation = Quaternion(1, -2.49197e-38, 7.54979e-08, -1.05879e-22)

[node name="RayFloor" type="RayCast3D" parent="Enemy/Skeleton" index="1"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.643772, 0.803052)
Expand All @@ -465,11 +465,11 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.643772, 0.310413)
target_position = Vector3(0, 0, 1.5)

[node name="AnimationPlayer" parent="Enemy" index="1"]
autoplay = "walk"
libraries = {
"": SubResource("AnimationLibrary_f4l5d"),
"extra": SubResource("AnimationLibrary_q27i1")
}
autoplay = "walk"

[node name="Sphere1" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.74185, 0.267137)
Expand Down
221 changes: 0 additions & 221 deletions 3d/platformer/export_presets.cfg

This file was deleted.

86 changes: 85 additions & 1 deletion 3d/platformer/game.tscn
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
[gd_scene load_steps=9 format=3 uid="uid://d0lrpf3mmjdsx"]
[gd_scene load_steps=12 format=3 uid="uid://d0lrpf3mmjdsx"]

[ext_resource type="PackedScene" uid="uid://dohp772jyjxb7" path="res://stage/stage.tscn" id="1_ybvw5"]
[ext_resource type="PackedScene" uid="uid://dfxo2jwbj4aeh" path="res://coin/coin.tscn" id="2_chew2"]
[ext_resource type="PackedScene" uid="uid://o5q0hy6cg6nt" path="res://enemy/enemy.tscn" id="3_nhwvs"]
[ext_resource type="PackedScene" uid="uid://cc4idhykjp5f5" path="res://player/player.tscn" id="4_ray4s"]
[ext_resource type="Script" path="res://touch_screen_ui.gd" id="5_7os5d"]
[ext_resource type="PackedScene" uid="uid://dmr0fcamx7t56" path="res://virtual_joystick/virtual_joystick_scene.tscn" id="5_smd4r"]

[sub_resource type="PhysicsMaterial" id="1"]
friction = 0.0
Expand All @@ -17,6 +19,8 @@ friction = 0.0
[sub_resource type="PhysicsMaterial" id="4"]
friction = 0.0

[sub_resource type="CanvasTexture" id="CanvasTexture_7o5bd"]

[node name="Game" type="Node3D"]

[node name="Stage" parent="." instance=ExtResource("1_ybvw5")]
Expand Down Expand Up @@ -264,3 +268,83 @@ physics_material_override = SubResource("4")

[node name="Player" parent="." instance=ExtResource("4_ray4s")]
transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, -9.49833, -3.84189, 3.9334)

[node name="touchScreenUi" type="CanvasLayer" parent="."]
script = ExtResource("5_7os5d")

[node name="Virtual Joystick" parent="touchScreenUi" instance=ExtResource("5_smd4r")]
deadzone_size = 0.0
clampzone_size = 100.0

[node name="performance" type="CheckButton" parent="touchScreenUi"]
anchors_preset = 1
anchor_left = 1.0
anchor_right = 1.0
offset_left = -197.0
offset_bottom = 31.0
grow_horizontal = 0
focus_mode = 0
text = "PERFORMANCE MODE"
alignment = 1
icon_alignment = 1
expand_icon = true

[node name="HBoxContainer" type="HBoxContainer" parent="touchScreenUi"]
anchors_preset = 6
anchor_left = 1.0
anchor_top = 0.5
anchor_right = 1.0
anchor_bottom = 0.5
offset_left = -256.0
offset_top = -64.0
offset_bottom = 64.0
grow_horizontal = 0
grow_vertical = 2

[node name="jump" type="Control" parent="touchScreenUi/HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3

[node name="Label" type="Label" parent="touchScreenUi/HBoxContainer/jump"]
z_index = 5
z_as_relative = false
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
text = "jump"
horizontal_alignment = 1
vertical_alignment = 1

[node name="jumpbtn" type="TouchScreenButton" parent="touchScreenUi/HBoxContainer/jump"]
self_modulate = Color(0, 0, 0, 1)
scale = Vector2(124, 124)
texture_normal = SubResource("CanvasTexture_7o5bd")
action = "jump"

[node name="shoot" type="Control" parent="touchScreenUi/HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3

[node name="shoot" type="Label" parent="touchScreenUi/HBoxContainer/shoot"]
z_index = 5
z_as_relative = false
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
text = "shoot"
horizontal_alignment = 1
vertical_alignment = 1

[node name="shoot2" type="TouchScreenButton" parent="touchScreenUi/HBoxContainer/shoot"]
self_modulate = Color(0, 0, 0, 1)
scale = Vector2(124, 124)
texture_normal = SubResource("CanvasTexture_7o5bd")
action = "shoot"

[connection signal="toggled" from="touchScreenUi/performance" to="touchScreenUi" method="_on_performance_toggled"]
3 changes: 3 additions & 0 deletions 3d/platformer/player/bullet/bullet.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ extends RigidBody3D
## If `true`, the bullet can hit enemies. This is set to `false` when the bullet
## hits an enemy so it can't hit an enemy multiple times while the bullet is fading out.
var enabled := true

func hide_omniLight() -> void:
$OmniLight3D.hide()
Loading