From 86c34c92649708d24ad4b21ba5c9430227d191ff Mon Sep 17 00:00:00 2001 From: "DavidCrompton1192@gmail.com" Date: Sun, 4 Jun 2023 19:28:16 -0400 Subject: [PATCH] Basic 3d Disc --- 3d_test.gd | 17 +++++++++++++++ 3d_test.tscn | 26 ++++++++++++++++++---- 3dobstacle.gd | 11 ++++++++++ art/TileMap.png.import | 13 +++++------ box_obstacle.tscn | 15 +++++++++++++ disc.tscn | 18 ++++++++++++++++ map_3d_test.gd | 11 ++++++++++ map_3d_test.tscn | 12 +++++++++-- player3d.gd | 49 ++++++++++++++++++++++++++++++++++++++++++ player3d.tscn | 48 +++++++++++++++++++++++++++++++++++++++-- project.godot | 6 ++++++ 11 files changed, 212 insertions(+), 14 deletions(-) create mode 100644 3d_test.gd create mode 100644 3dobstacle.gd create mode 100644 box_obstacle.tscn create mode 100644 disc.tscn create mode 100644 map_3d_test.gd create mode 100644 player3d.gd diff --git a/3d_test.gd b/3d_test.gd new file mode 100644 index 0000000..5f1afc7 --- /dev/null +++ b/3d_test.gd @@ -0,0 +1,17 @@ +extends Node3D + +const Disc = preload("res://disc.tscn") + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + +func _input(event): + if event.is_action_pressed("player_jump"): + var disc = Disc.instantiate() + disc.position = $Player/Torso/RightArm/Hand.global_position + add_child(disc) + disc.apply_impulse(Vector3(0,10,0)) +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass diff --git a/3d_test.tscn b/3d_test.tscn index d4fc957..e703dbc 100644 --- a/3d_test.tscn +++ b/3d_test.tscn @@ -1,9 +1,18 @@ -[gd_scene load_steps=3 format=3 uid="uid://b6qd2ja2kaul8"] +[gd_scene load_steps=6 format=3 uid="uid://b6qd2ja2kaul8"] +[ext_resource type="Script" path="res://3d_test.gd" id="1_o7asi"] [ext_resource type="PackedScene" uid="uid://ctgbbvgfnocql" path="res://player3d.tscn" id="1_osef0"] [ext_resource type="PackedScene" uid="uid://fjxeinktml2j" path="res://map_3d_test.tscn" id="2_3miw1"] +[ext_resource type="Script" path="res://map_3d_test.gd" id="3_15ip2"] +[ext_resource type="PackedScene" uid="uid://cb4hfwfbpcqy4" path="res://box_obstacle.tscn" id="3_qc72a"] [node name="Node3D" type="Node3D"] +script = ExtResource("1_o7asi") + +[node name="Sun" type="DirectionalLight3D" parent="."] +transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 9.82951, 0) +shadow_enabled = true +directional_shadow_pancake_size = 0.0 [node name="Player" parent="." instance=ExtResource("1_osef0")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.58914, 0) @@ -12,7 +21,16 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.58914, 0) transform = Transform3D(1, 0, 0, 0, 0.979855, 0.19971, 0, -0.19971, 0.979855, 0, 1.43735, 2.24099) [node name="TestTerrain" parent="." instance=ExtResource("2_3miw1")] +script = ExtResource("3_15ip2") -[node name="DirectionalLight3D" type="DirectionalLight3D" parent="TestTerrain"] -transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 9.82951, 0) -shadow_enabled = true +[node name="Box" parent="." instance=ExtResource("3_qc72a")] +transform = Transform3D(1, 0, 0, 0, -1, -8.74228e-08, 0, 8.74228e-08, -1, 20.5883, 0.829506, -4.05434) + +[node name="Box2" parent="." instance=ExtResource("3_qc72a")] +transform = Transform3D(1, 0, 0, 0, -1, -8.74228e-08, 0, 8.74228e-08, -1, 7.65501, 0.829506, 7.05613) + +[node name="Box3" parent="." instance=ExtResource("3_qc72a")] +transform = Transform3D(1, 0, 0, 0, -1, -8.74228e-08, 0, 8.74228e-08, -1, 0, 0.829506, -6) + +[node name="Box4" parent="." instance=ExtResource("3_qc72a")] +transform = Transform3D(1, 0, 0, 0, -1, -8.74228e-08, 0, 8.74228e-08, -1, -10.006, 0.829506, -6) diff --git a/3dobstacle.gd b/3dobstacle.gd new file mode 100644 index 0000000..e08925d --- /dev/null +++ b/3dobstacle.gd @@ -0,0 +1,11 @@ +extends Node + + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass diff --git a/art/TileMap.png.import b/art/TileMap.png.import index b1c5d18..f888dee 100644 --- a/art/TileMap.png.import +++ b/art/TileMap.png.import @@ -3,25 +3,26 @@ importer="texture" type="CompressedTexture2D" uid="uid://bbmlq6lulxkdc" -path="res://.godot/imported/TileMap.png-b7cc102f901c5c8b07c5f5b72d97252e.ctex" +path.s3tc="res://.godot/imported/TileMap.png-b7cc102f901c5c8b07c5f5b72d97252e.s3tc.ctex" metadata={ -"vram_texture": false +"imported_formats": ["s3tc_bptc"], +"vram_texture": true } [deps] source_file="res://art/TileMap.png" -dest_files=["res://.godot/imported/TileMap.png-b7cc102f901c5c8b07c5f5b72d97252e.ctex"] +dest_files=["res://.godot/imported/TileMap.png-b7cc102f901c5c8b07c5f5b72d97252e.s3tc.ctex"] [params] -compress/mode=0 +compress/mode=2 compress/high_quality=false compress/lossy_quality=0.7 compress/hdr_compression=1 compress/normal_map=0 compress/channel_pack=0 -mipmaps/generate=false +mipmaps/generate=true mipmaps/limit=-1 roughness/mode=0 roughness/src_normal="" @@ -31,4 +32,4 @@ process/normal_map_invert_y=false process/hdr_as_srgb=false process/hdr_clamp_exposure=false process/size_limit=0 -detect_3d/compress_to=1 +detect_3d/compress_to=0 diff --git a/box_obstacle.tscn b/box_obstacle.tscn new file mode 100644 index 0000000..8433517 --- /dev/null +++ b/box_obstacle.tscn @@ -0,0 +1,15 @@ +[gd_scene load_steps=3 format=3 uid="uid://cb4hfwfbpcqy4"] + +[sub_resource type="BoxMesh" id="BoxMesh_mpwqk"] +size = Vector3(1, 2, 1) + +[sub_resource type="BoxShape3D" id="BoxShape3D_ocyf5"] +size = Vector3(1, 2, 1) + +[node name="StaticBody3D" type="StaticBody3D"] + +[node name="MeshInstance3D" type="MeshInstance3D" parent="."] +mesh = SubResource("BoxMesh_mpwqk") + +[node name="CollisionShape3D" type="CollisionShape3D" parent="."] +shape = SubResource("BoxShape3D_ocyf5") diff --git a/disc.tscn b/disc.tscn new file mode 100644 index 0000000..5263978 --- /dev/null +++ b/disc.tscn @@ -0,0 +1,18 @@ +[gd_scene load_steps=3 format=3 uid="uid://bm6vv074tk0nx"] + +[sub_resource type="CylinderMesh" id="CylinderMesh_f68ox"] +top_radius = 0.25 +bottom_radius = 0.25 +height = 0.05 + +[sub_resource type="CylinderShape3D" id="CylinderShape3D_6l5gm"] +height = 0.05 +radius = 0.25 + +[node name="Disc" type="RigidBody3D"] + +[node name="Model" type="MeshInstance3D" parent="."] +mesh = SubResource("CylinderMesh_f68ox") + +[node name="CollisionShape3D" type="CollisionShape3D" parent="."] +shape = SubResource("CylinderShape3D_6l5gm") diff --git a/map_3d_test.gd b/map_3d_test.gd new file mode 100644 index 0000000..593ccbd --- /dev/null +++ b/map_3d_test.gd @@ -0,0 +1,11 @@ +extends StaticBody3D + + + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass diff --git a/map_3d_test.tscn b/map_3d_test.tscn index ef6f1c0..023ebd4 100644 --- a/map_3d_test.tscn +++ b/map_3d_test.tscn @@ -1,9 +1,17 @@ -[gd_scene load_steps=2 format=3 uid="uid://fjxeinktml2j"] +[gd_scene load_steps=4 format=3 uid="uid://fjxeinktml2j"] [sub_resource type="PlaneMesh" id="PlaneMesh_763vg"] size = Vector2(100, 100) +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_2fd53"] + +[sub_resource type="WorldBoundaryShape3D" id="WorldBoundaryShape3D_xh6w0"] + [node name="Terrain" type="StaticBody3D"] -[node name="MeshInstance3D" type="MeshInstance3D" parent="."] +[node name="Plane" type="MeshInstance3D" parent="."] mesh = SubResource("PlaneMesh_763vg") +surface_material_override/0 = SubResource("StandardMaterial3D_2fd53") + +[node name="WorldPlane" type="CollisionShape3D" parent="."] +shape = SubResource("WorldBoundaryShape3D_xh6w0") diff --git a/player3d.gd b/player3d.gd new file mode 100644 index 0000000..957d271 --- /dev/null +++ b/player3d.gd @@ -0,0 +1,49 @@ +extends CharacterBody3D + +var remote_player = false + +const SPEED = 5.0 +const JUMP_VELOCITY = 4.5 + +# Get the gravity from the project settings to be synced with RigidBody nodes. +var gravity = ProjectSettings.get_setting("physics/3d/default_gravity") + +func _input(event): + pass + +func _physics_process(delta): + # Add the gravity. + if not is_on_floor(): + velocity.y -= gravity * delta + + # Handle Jump. + if Input.is_action_just_pressed("player_jump") and is_on_floor(): + velocity.y = JUMP_VELOCITY + + # 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("player_left", "player_right", "player_up", "player_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) + + var flick = Input.get_vector( + "flick_left", + "flick_right", + "flick_up", + "flick_down" + ) + + var flick_ang :float= 0 + if flick.length_squared() != 0: + flick_ang = flick.angle() + var flick_rot = Vector3(0,0,flick_ang) + $Torso/LeftArm.rotation = flick_rot + $Torso/RightArm.rotation = -flick_rot + + move_and_slide() diff --git a/player3d.tscn b/player3d.tscn index 95097ba..c665203 100644 --- a/player3d.tscn +++ b/player3d.tscn @@ -1,14 +1,58 @@ -[gd_scene load_steps=3 format=3 uid="uid://ctgbbvgfnocql"] +[gd_scene load_steps=6 format=3 uid="uid://ctgbbvgfnocql"] + +[ext_resource type="Script" path="res://player3d.gd" id="1_8eds3"] [sub_resource type="BoxShape3D" id="BoxShape3D_vyj2w"] size = Vector3(1, 2, 1) [sub_resource type="CapsuleMesh" id="CapsuleMesh_8g2hv"] +[sub_resource type="CapsuleMesh" id="CapsuleMesh_1k7yw"] +radius = 0.175 +height = 1.25 + +[sub_resource type="SphereShape3D" id="SphereShape3D_1okp8"] +radius = 0.25 + [node name="Player" type="CharacterBody3D"] +script = ExtResource("1_8eds3") [node name="CollisionShape3D" type="CollisionShape3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0) shape = SubResource("BoxShape3D_vyj2w") -[node name="MeshInstance3D" type="MeshInstance3D" parent="."] +[node name="Torso" type="MeshInstance3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0) mesh = SubResource("CapsuleMesh_8g2hv") + +[node name="LeftArm" type="Node3D" parent="Torso"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.5, 0.2, 0) + +[node name="Arm" type="MeshInstance3D" parent="Torso/LeftArm"] +transform = Transform3D(-4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0, 1, -0.4, 0, 0) +mesh = SubResource("CapsuleMesh_1k7yw") +skeleton = NodePath("../../..") + +[node name="LeftHand" type="StaticBody3D" parent="Torso/LeftArm"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1, 0, 0) +collision_layer = 2 +collision_mask = 2 + +[node name="LeftHand" type="CollisionShape3D" parent="Torso/LeftArm/LeftHand"] +shape = SubResource("SphereShape3D_1okp8") + +[node name="RightArm" type="Node3D" parent="Torso"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.5, 0.2, 0) + +[node name="Arm" type="MeshInstance3D" parent="Torso/RightArm"] +transform = Transform3D(-4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0, 1, 0.4, 0, 0) +mesh = SubResource("CapsuleMesh_1k7yw") +skeleton = NodePath("../../..") + +[node name="Hand" type="StaticBody3D" parent="Torso/RightArm"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0) +collision_layer = 2 +collision_mask = 2 + +[node name="Hand" type="CollisionShape3D" parent="Torso/RightArm/Hand"] +shape = SubResource("SphereShape3D_1okp8") diff --git a/project.godot b/project.godot index 6e563c3..d410d15 100644 --- a/project.godot +++ b/project.godot @@ -53,6 +53,12 @@ player_down={ , Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":1.0,"script":null) ] } +player_jump={ +"deadzone": 0.5, +"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":32,"key_label":0,"unicode":32,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":true,"script":null) +] +} flick_up={ "deadzone": 0.5, "events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":-1.0,"script":null)