Add camera height slider

This commit is contained in:
Sofia 2024-08-20 16:58:22 +03:00
parent 5cb1777149
commit d0fbc077ec
6 changed files with 103 additions and 50 deletions

View File

@ -156,6 +156,16 @@ toggle_noclip={
"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":4194334,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
zoom_orbit_out={
"deadzone": 0.5,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":8,"position":Vector2(310, 20),"global_position":Vector2(324, 90),"factor":1.0,"button_index":4,"canceled":false,"pressed":true,"double_click":false,"script":null)
]
}
zoom_orbit_in={
"deadzone": 0.5,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":16,"position":Vector2(336, 24),"global_position":Vector2(350, 94),"factor":1.0,"button_index":5,"canceled":false,"pressed":true,"double_click":false,"script":null)
]
}
[internationalization]

View File

@ -2,7 +2,7 @@
[ext_resource type="Script" path="res://scripts/Hud.cs" id="1_hvqpl"]
[node name="HUD" type="Control" node_paths=PackedStringArray("HoverText")]
[node name="HUD" type="Control" node_paths=PackedStringArray("HoverText", "CameraHeightContainer", "CameraHeightSlider")]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
@ -11,26 +11,9 @@ 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 = -94.0
offset_top = -163.0
offset_right = 95.0
grow_horizontal = 2
grow_vertical = 0
theme_override_font_sizes/normal_font_size = 32
bbcode_enabled = true
text = "[Hover Text]"
fit_content = true
scroll_active = false
autowrap_mode = 0
HoverText = NodePath("CenterContainer2/HoverText")
CameraHeightContainer = NodePath("CameraHeightContainer")
CameraHeightSlider = NodePath("CameraHeightContainer/CameraHeightSlider")
[node name="CenterContainer" type="CenterContainer" parent="."]
layout_mode = 1
@ -49,3 +32,47 @@ mouse_filter = 1
custom_minimum_size = Vector2(2, 16)
layout_mode = 2
mouse_filter = 1
[node name="CameraHeightContainer" type="VBoxContainer" parent="."]
visible = false
layout_mode = 1
anchors_preset = 2
anchor_top = 1.0
anchor_bottom = 1.0
offset_top = -227.0
offset_right = 67.0
grow_vertical = 0
[node name="CameraHeightSlider" type="VSlider" parent="CameraHeightContainer"]
custom_minimum_size = Vector2(70, 200)
layout_mode = 2
step = 0.1
[node name="CameraHeightLabel" type="Label" parent="CameraHeightContainer"]
layout_mode = 2
text = "Height
"
horizontal_alignment = 1
[node name="CenterContainer2" type="CenterContainer" 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 = -94.0
offset_top = -118.59
offset_right = 95.0
offset_bottom = -73.59
grow_horizontal = 2
grow_vertical = 0
[node name="HoverText" type="RichTextLabel" parent="CenterContainer2"]
layout_mode = 2
theme_override_font_sizes/normal_font_size = 32
bbcode_enabled = true
text = "[Hover Text]"
fit_content = true
scroll_active = false
autowrap_mode = 0

View File

@ -17,7 +17,7 @@ size = Vector3(5, 5, 5)
size = Vector3(5, 5, 5)
[sub_resource type="BoxShape3D" id="BoxShape3D_3kmm7"]
size = Vector3(1.3, 0.2, 2.4)
size = Vector3(5, 0.2, 5)
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_sxhnw"]
transparency = 1
@ -78,33 +78,14 @@ shape = SubResource("BoxShape3D_5k7xn")
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 6, 0)
shape = SubResource("BoxShape3D_3kmm7")
[node name="TableWalls" type="StaticBody3D" parent="TableWalls"]
collision_layer = 2
collision_mask = 2
[node name="Wall1" type="CollisionShape3D" parent="TableWalls/TableWalls"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.6, 3.66627)
shape = SubResource("BoxShape3D_kn6mn")
[node name="Wall2" type="CollisionShape3D" parent="TableWalls/TableWalls"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.6, -3.69933)
shape = SubResource("BoxShape3D_kn6mn")
[node name="Wall3" type="CollisionShape3D" parent="TableWalls/TableWalls"]
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, -3.1173, 3.6, 0)
shape = SubResource("BoxShape3D_5k7xn")
[node name="Wall4" type="CollisionShape3D" parent="TableWalls/TableWalls"]
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 3.1173, 3.6, 0)
shape = SubResource("BoxShape3D_5k7xn")
[node name="Roof" type="CollisionShape3D" parent="TableWalls/TableWalls"]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 6, 0)
[node name="Floor" type="CollisionShape3D" parent="TableWalls"]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0.992982, 0)
shape = SubResource("BoxShape3D_3kmm7")
[node name="Orbit" type="Node3D" parent="." node_paths=PackedStringArray("Camera", "Hand")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.12311, 0)
script = ExtResource("4_nyqjn")
MaxCameraDistance = 2.0
Camera = NodePath("OrbitCamera")
Hand = NodePath("OrbitCamera/OrbitHand")
@ -116,6 +97,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.3, -0.1, -0.26)
[node name="Plane" type="StaticBody3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.37762, 0)
visible = false
collision_layer = 16
collision_mask = 16

View File

@ -9,6 +9,10 @@ namespace Gmtk24 {
public RichTextLabel HoverText;
[Export]
public bool InteractionPaused = false;
[Export]
public Container CameraHeightContainer;
[Export]
public Slider CameraHeightSlider;
private Interactible Hovered;

View File

@ -8,13 +8,21 @@ namespace Gmtk24 {
[Signal]
public delegate void DraggingHeldBlockEventHandler(BuildingBlock block);
[ExportCategory("Camera")]
[Export(PropertyHint.Range, "0,10,0.1")]
public float MaxCameraDistance = 1f;
[Export(PropertyHint.Range, "0,10,0.1")]
public float MinCameraDistance = 0.1f;
[Export(PropertyHint.Range, "0,10,0.1")]
public float MinCameraHeight = 1.123f;
[Export(PropertyHint.Range, "0,10,0.1")]
public float MaxCameraHeight = 5f;
[Export(PropertyHint.Range, "0,10,0.1")]
public float CameraZoomTick = 0.1f;
[Export]
public Camera3D Camera;
[ExportCategory("Hand")]
[Export]
public Node3D Hand;
[Export]
@ -24,9 +32,14 @@ namespace Gmtk24 {
[Export]
public float DragDistanceTreshold = 500f;
[ExportCategory("Debug")]
[Export]
public bool IsEnabled { private set; get; } = false;
public Hud Hud;
private float CurrentZoom = 1f;
private float CurrentHeight = 0;
private float CurrentYaw = 0;
private float CurrentPitch = 0;
@ -38,10 +51,19 @@ namespace Gmtk24 {
// Called when the node enters the scene tree for the first time.
public override void _Ready() {
CurrentPitch = -(float)Math.PI * 0.25f;
CurrentYaw = (float)Math.PI * 0.5f;
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta) {
if (Hud != null) {
var diff = MaxCameraHeight - MinCameraHeight;
CurrentHeight = (float)(Hud.CameraHeightSlider.Value / Hud.CameraHeightSlider.MaxValue * diff + MinCameraHeight);
}
Position = Vector3.Up * CurrentHeight;
Camera.Position = new Vector3(0, 0, CurrentZoom);
Quaternion = new Quaternion(Vector3.Up, CurrentYaw) * new Quaternion(Vector3.Right, CurrentPitch);
if (HeldBlock != null) {
HeldBlock.Position = HeldBlock.Position.Lerp(Vector3.Zero, 0.2f);
@ -64,6 +86,7 @@ namespace Gmtk24 {
Input.MouseMode = Input.MouseModeEnum.Visible;
else
Input.MouseMode = Input.MouseModeEnum.Captured;
Hud.CameraHeightContainer.Visible = enabled;
}
public override void _UnhandledInput(InputEvent @event) {
@ -110,6 +133,13 @@ namespace Gmtk24 {
if (@event.IsActionPressed("rotate_block_left")) {
HeldBlock.RotateY(-RotateAmt);
}
} else {
if (@event.IsActionPressed("zoom_orbit_out")) {
CurrentZoom = Math.Clamp(CurrentZoom - CameraZoomTick, MinCameraDistance, MaxCameraDistance);
}
if (@event.IsActionPressed("zoom_orbit_in")) {
CurrentZoom = Math.Clamp(CurrentZoom + CameraZoomTick, MinCameraDistance, MaxCameraDistance);
}
}
}

View File

@ -38,6 +38,8 @@ namespace Gmtk24 {
// Called when the node enters the scene tree for the first time.
public override void _Ready() {
Orbit.Hud = Hud;
Vector3 SpawnPos = Vector3.Zero;
if (SpawnPoint != null)
@ -87,11 +89,9 @@ namespace Gmtk24 {
var res = Util.RaycastFromMouse(Orbit.Camera, 0b10100 | PlaneOnlyLayer);
if (res is RaycastResult results) {
Vector3 LocalPos = results.Position - GlobalPosition;
if (results.Collider is BuildingBlock || results.Collider == Plane) {
GhostBlockNormal = results.Normal;
Vector3 offset = GhostBlock.OffsetFrom(results.Normal, GhostOnlyMask);
LocalPos += offset;
}
GhostBlockNormal = results.Normal;
Vector3 offset = GhostBlock.OffsetFrom(results.Normal, GhostOnlyMask);
LocalPos += offset;
GhostBlock.Position = LocalPos * Basis;
}