Add interacting, maybe
This commit is contained in:
parent
eac93e3f97
commit
f6b7f9e319
@ -121,6 +121,11 @@ toggle_pause_menu={
|
||||
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":6,"pressure":0.0,"pressed":true,"script":null)
|
||||
]
|
||||
}
|
||||
interact={
|
||||
"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":69,"key_label":0,"unicode":101,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[internationalization]
|
||||
|
||||
|
@ -1,9 +1,10 @@
|
||||
[gd_scene load_steps=8 format=3 uid="uid://8po7ftboqq4k"]
|
||||
[gd_scene load_steps=9 format=3 uid="uid://8po7ftboqq4k"]
|
||||
|
||||
[ext_resource type="CameraAttributesPhysical" uid="uid://cxyj2tvfksjl6" path="res://scenes/hazy_env_camera_attrs.tres" id="1_r2j1d"]
|
||||
[ext_resource type="PackedScene" uid="uid://br315evr8x2gt" path="res://scenes/hazy_env.tscn" id="2_le85m"]
|
||||
[ext_resource type="LightmapGIData" uid="uid://bp05p4yab2ukx" path="res://scenes/demo/demo.lmbake" id="2_thfwf"]
|
||||
[ext_resource type="PackedScene" uid="uid://bqts60gpnb82d" path="res://scenes/demo/demo_map.tscn" id="4_0ojvw"]
|
||||
[ext_resource type="PackedScene" uid="uid://b5asfx4vribls" path="res://scenes/interface/hud.tscn" id="7_g7tfv"]
|
||||
[ext_resource type="PackedScene" uid="uid://wjbuh7jk50nm" path="res://scenes/player.tscn" id="10_3xiy2"]
|
||||
[ext_resource type="PackedScene" uid="uid://d02cqylu3xwos" path="res://scenes/table.tscn" id="11_7trvw"]
|
||||
[ext_resource type="PackedScene" uid="uid://c670g1qg5gaug" path="res://scenes/interface/pause_menu.tscn" id="11_lav3p"]
|
||||
@ -52,9 +53,12 @@ size = Vector3(43.3174, 26.5295, 43.4319)
|
||||
[node name="Player" parent="." instance=ExtResource("10_3xiy2")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.332064, 1.5426, 3.65156)
|
||||
|
||||
[node name="PauseMenu" parent="." instance=ExtResource("11_lav3p")]
|
||||
|
||||
[node name="table" parent="." node_paths=PackedStringArray("TrenchbroomMap") instance=ExtResource("11_7trvw")]
|
||||
transform = Transform3D(-0.0123217, 0, 0.999924, 0, 1, 0, -0.999924, 0, -0.0123217, 0, 0, 0)
|
||||
TrenchbroomMap = NodePath("../DemoMap")
|
||||
RelativeScale = 0.005
|
||||
|
||||
[node name="HUD" parent="." node_paths=PackedStringArray("Player") instance=ExtResource("7_g7tfv")]
|
||||
Player = NodePath("../Player")
|
||||
|
||||
[node name="PauseMenu" parent="." instance=ExtResource("11_lav3p")]
|
||||
|
52
scenes/interface/hud.tscn
Normal file
52
scenes/interface/hud.tscn
Normal file
@ -0,0 +1,52 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://b5asfx4vribls"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/Hud.cs" id="1_hvqpl"]
|
||||
|
||||
[node name="HUD" type="Control" node_paths=PackedStringArray("HoverText")]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
mouse_filter = 2
|
||||
script = ExtResource("1_hvqpl")
|
||||
HoverText = NodePath("HoverText")
|
||||
|
||||
[node name="HoverText" type="RichTextLabel" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 7
|
||||
anchor_left = 0.5
|
||||
anchor_top = 1.0
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 1.0
|
||||
offset_left = -180.5
|
||||
offset_top = -166.0
|
||||
offset_right = 180.5
|
||||
offset_bottom = -78.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 0
|
||||
theme_override_font_sizes/normal_font_size = 64
|
||||
bbcode_enabled = true
|
||||
text = "[Hover Text]"
|
||||
fit_content = true
|
||||
scroll_active = false
|
||||
autowrap_mode = 0
|
||||
|
||||
[node name="CenterContainer" type="CenterContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="CenterContainer"]
|
||||
custom_minimum_size = Vector2(16, 2)
|
||||
layout_mode = 2
|
||||
mouse_filter = 1
|
||||
|
||||
[node name="ColorRect2" type="ColorRect" parent="CenterContainer"]
|
||||
custom_minimum_size = Vector2(2, 16)
|
||||
layout_mode = 2
|
||||
mouse_filter = 1
|
@ -8,12 +8,13 @@
|
||||
height = 1.9
|
||||
radius = 0.3
|
||||
|
||||
[node name="Player" type="CharacterBody3D" node_paths=PackedStringArray("Eye", "HeightBasedWindPlayer", "FootstepPlayer")]
|
||||
[node name="Player" type="CharacterBody3D" node_paths=PackedStringArray("Eye", "LookingAt", "HeightBasedWindPlayer", "FootstepPlayer")]
|
||||
script = ExtResource("1_aff2a")
|
||||
MovementSpeed = 4.0
|
||||
JumpVelocity = 5.0
|
||||
Gravity = 13.0
|
||||
Eye = NodePath("PlayerEyeCamera")
|
||||
LookingAt = NodePath("PlayerEyeCamera/LookAt")
|
||||
HeightBasedWindPlayer = NodePath("HeightBasedWindFx")
|
||||
MinVolumeWindHeight = -5.0
|
||||
MaxVolumeWindHeight = 20.0
|
||||
@ -26,27 +27,16 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.7, 0)
|
||||
[node name="Ears" type="AudioListener3D" parent="PlayerEyeCamera"]
|
||||
current = true
|
||||
|
||||
[node name="LookAt" type="RayCast3D" parent="PlayerEyeCamera"]
|
||||
target_position = Vector3(0, 0, -4)
|
||||
collision_mask = 4
|
||||
debug_shape_custom_color = Color(1, 1, 1, 1)
|
||||
debug_shape_thickness = 5
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.95, 0)
|
||||
shape = SubResource("CylinderShape3D_rgktv")
|
||||
|
||||
[node name="CenterContainer" type="CenterContainer" parent="."]
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="CenterContainer"]
|
||||
custom_minimum_size = Vector2(16, 2)
|
||||
layout_mode = 2
|
||||
mouse_filter = 1
|
||||
|
||||
[node name="ColorRect2" type="ColorRect" parent="CenterContainer"]
|
||||
custom_minimum_size = Vector2(2, 16)
|
||||
layout_mode = 2
|
||||
mouse_filter = 1
|
||||
|
||||
[node name="HeightBasedWindFx" type="AudioStreamPlayer" parent="."]
|
||||
process_mode = 3
|
||||
stream = ExtResource("2_ab4w4")
|
||||
|
@ -5,7 +5,7 @@
|
||||
[ext_resource type="Material" uid="uid://bq5oqyuwekryv" path="res://textures/building_block.tres" id="2_1s35y"]
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_iiew7"]
|
||||
size = Vector3(1.26587, 0.102112, 2.3989)
|
||||
size = Vector3(1.26587, 1.10037, 2.3989)
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_kn6mn"]
|
||||
size = Vector3(1.3, 5, 0.01)
|
||||
@ -17,38 +17,43 @@ size = Vector3(2.4, 5, 0.01)
|
||||
size = Vector3(1.3, 0.2, 2.4)
|
||||
|
||||
[node name="table" type="StaticBody3D" node_paths=PackedStringArray("SpawnPoint")]
|
||||
collision_layer = 3
|
||||
collision_mask = 3
|
||||
collision_layer = 7
|
||||
collision_mask = 7
|
||||
script = ExtResource("1_cb7s1")
|
||||
BlockMaterial = ExtResource("2_1s35y")
|
||||
SpawnPoint = NodePath("SpawnPoint")
|
||||
BlockMask = 2
|
||||
InteractName = "build"
|
||||
|
||||
[node name="table" parent="." instance=ExtResource("1_1soa3")]
|
||||
|
||||
[node name="TableCollider" type="CollisionShape3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.00354004, 1.05606, -0.00126699)
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.00354004, 0.55693, -0.00126699)
|
||||
shape = SubResource("BoxShape3D_iiew7")
|
||||
|
||||
[node name="SpawnPoint" type="Node3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.7677, 0)
|
||||
|
||||
[node name="Wall1" type="CollisionShape3D" parent="."]
|
||||
[node name="TableWalls" type="StaticBody3D" parent="."]
|
||||
collision_layer = 2
|
||||
collision_mask = 2
|
||||
|
||||
[node name="Wall1" type="CollisionShape3D" parent="TableWalls"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.6, 1.2)
|
||||
shape = SubResource("BoxShape3D_kn6mn")
|
||||
|
||||
[node name="Wall2" type="CollisionShape3D" parent="."]
|
||||
[node name="Wall2" type="CollisionShape3D" parent="TableWalls"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.6, -1.2)
|
||||
shape = SubResource("BoxShape3D_kn6mn")
|
||||
|
||||
[node name="Wall3" type="CollisionShape3D" parent="."]
|
||||
[node name="Wall3" type="CollisionShape3D" parent="TableWalls"]
|
||||
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, -0.65, 3.6, 0)
|
||||
shape = SubResource("BoxShape3D_5k7xn")
|
||||
|
||||
[node name="Wall4" type="CollisionShape3D" parent="."]
|
||||
[node name="Wall4" type="CollisionShape3D" parent="TableWalls"]
|
||||
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 0.65, 3.6, 0)
|
||||
shape = SubResource("BoxShape3D_5k7xn")
|
||||
|
||||
[node name="Roof" type="CollisionShape3D" parent="."]
|
||||
[node name="Roof" type="CollisionShape3D" parent="TableWalls"]
|
||||
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 6, 0)
|
||||
shape = SubResource("BoxShape3D_3kmm7")
|
||||
|
64
scripts/Hud.cs
Normal file
64
scripts/Hud.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using Godot;
|
||||
using System.Text;
|
||||
|
||||
namespace Gmtk24 {
|
||||
public partial class Hud : Control {
|
||||
[Export]
|
||||
public Player Player;
|
||||
[Export]
|
||||
public RichTextLabel HoverText;
|
||||
|
||||
private Interactible Hovered;
|
||||
|
||||
public override void _Process(double delta) {
|
||||
if (Player == null)
|
||||
return;
|
||||
|
||||
GodotObject collider;
|
||||
if (Input.MouseMode == Input.MouseModeEnum.Captured) {
|
||||
collider = Player.LookingAt.GetCollider();
|
||||
} else {
|
||||
var viewport = GetViewport();
|
||||
var camera = GetViewport().GetCamera3D();
|
||||
var origin = camera.ProjectRayOrigin(viewport.GetMousePosition());
|
||||
var normal = camera.ProjectRayNormal(viewport.GetMousePosition());
|
||||
var ray = new PhysicsRayQueryParameters3D {
|
||||
From = origin,
|
||||
To = normal,
|
||||
CollideWithBodies = true,
|
||||
CollisionMask = 0b100,
|
||||
HitBackFaces = false,
|
||||
HitFromInside = false,
|
||||
};
|
||||
var results = camera.GetWorld3D().DirectSpaceState.IntersectRay(ray);
|
||||
|
||||
if (results.ContainsKey("collider")) {
|
||||
collider = (GodotObject)results["collider"];
|
||||
} else {
|
||||
collider = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (collider is Interactible interactible) {
|
||||
Hovered = interactible;
|
||||
|
||||
StringBuilder Builder = new StringBuilder();
|
||||
foreach (var e in InputMap.ActionGetEvents("interact")) {
|
||||
Builder.Append($"{e.AsText().Replace("(Physical)", "")}: {interactible.InteractName}");
|
||||
}
|
||||
|
||||
HoverText.Text = Builder.ToString();
|
||||
} else {
|
||||
Hovered = null;
|
||||
HoverText.Text = "";
|
||||
}
|
||||
}
|
||||
|
||||
public override void _UnhandledInput(InputEvent @event) {
|
||||
if (@event.IsActionPressed("interact") && Hovered != null) {
|
||||
Hovered.HandleInput(@event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
16
scripts/Interactible.cs
Normal file
16
scripts/Interactible.cs
Normal file
@ -0,0 +1,16 @@
|
||||
|
||||
using Godot;
|
||||
|
||||
namespace Gmtk24 {
|
||||
public partial class Interactible : StaticBody3D {
|
||||
[Signal]
|
||||
public delegate void OnInteractedEventHandler(InputEvent e);
|
||||
|
||||
[Export]
|
||||
public string InteractName;
|
||||
|
||||
public void HandleInput(InputEvent e) {
|
||||
EmitSignal(SignalName.OnInteracted, e);
|
||||
}
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ using Godot;
|
||||
|
||||
namespace Gmtk24 {
|
||||
public partial class Player : CharacterBody3D {
|
||||
[ExportCategory("Movement")]
|
||||
[Export]
|
||||
public float MovementSpeed = 7;
|
||||
[Export]
|
||||
@ -12,8 +13,11 @@ namespace Gmtk24 {
|
||||
public float JumpBufferLengthSeconds = 0.2f;
|
||||
[Export]
|
||||
public float Gravity = 20;
|
||||
[ExportCategory("Vision")]
|
||||
[Export]
|
||||
public Node3D Eye;
|
||||
[Export]
|
||||
public RayCast3D LookingAt;
|
||||
[ExportCategory("Noises")]
|
||||
[Export]
|
||||
public AudioStreamPlayer HeightBasedWindPlayer;
|
||||
|
@ -1,11 +1,8 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
||||
|
||||
namespace Gmtk24 {
|
||||
public partial class Table : StaticBody3D {
|
||||
public partial class Table : Interactible {
|
||||
[Export(PropertyHint.NodeType, "FuncGodotMap")]
|
||||
public Node3D TrenchbroomMap;
|
||||
[Export(PropertyHint.Range, "0.005,0.1,0.005,or_greater")]
|
||||
@ -25,6 +22,10 @@ namespace Gmtk24 {
|
||||
SpawnPos = SpawnPoint.GlobalPosition - GlobalPosition;
|
||||
|
||||
SpawnBlocks(SpawnPos);
|
||||
|
||||
OnInteracted += (e) => {
|
||||
GD.Print("hello!");
|
||||
};
|
||||
}
|
||||
|
||||
public void SpawnBlocks(Vector3 position) {
|
||||
@ -47,5 +48,6 @@ namespace Gmtk24 {
|
||||
AddChild(block);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user