Merge pull request #31 from Nitwel/testing
Add collision shapes to the walls
This commit is contained in:
commit
fdf3b66a3e
|
@ -7,6 +7,7 @@ extends Node3D
|
||||||
@onready var menu_room: Node3D = $Content/RoomMenu
|
@onready var menu_room: Node3D = $Content/RoomMenu
|
||||||
@onready var nav_automate = $Navigation/Automate
|
@onready var nav_automate = $Navigation/Automate
|
||||||
@onready var nav_settings = $Navigation/Settings
|
@onready var nav_settings = $Navigation/Settings
|
||||||
|
@onready var menu_settings: Node3D = $Content/SettingsMenu
|
||||||
|
|
||||||
enum Menu {
|
enum Menu {
|
||||||
VIEW,
|
VIEW,
|
||||||
|
@ -77,4 +78,4 @@ func enum_to_menu(menu: Menu):
|
||||||
Menu.AUTOMATE:
|
Menu.AUTOMATE:
|
||||||
return null
|
return null
|
||||||
Menu.SETTINGS:
|
Menu.SETTINGS:
|
||||||
return null
|
return menu_settings
|
|
@ -1,4 +1,4 @@
|
||||||
[gd_scene load_steps=12 format=3 uid="uid://c3kdssrmv84kv"]
|
[gd_scene load_steps=13 format=3 uid="uid://c3kdssrmv84kv"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://content/ui/menu/menu.gd" id="1_ng4u3"]
|
[ext_resource type="Script" path="res://content/ui/menu/menu.gd" id="1_ng4u3"]
|
||||||
[ext_resource type="PackedScene" uid="uid://crrb0l3ekuotj" path="res://content/ui/menu/edit/edit_menu.tscn" id="4_r2raj"]
|
[ext_resource type="PackedScene" uid="uid://crrb0l3ekuotj" path="res://content/ui/menu/edit/edit_menu.tscn" id="4_r2raj"]
|
||||||
|
@ -10,6 +10,7 @@
|
||||||
[ext_resource type="Texture2D" uid="uid://dch6rwihrl3i2" path="res://assets/icons/schema_white_24dp.svg" id="8_3d082"]
|
[ext_resource type="Texture2D" uid="uid://dch6rwihrl3i2" path="res://assets/icons/schema_white_24dp.svg" id="8_3d082"]
|
||||||
[ext_resource type="Texture2D" uid="uid://dyh0ax51xqp8n" path="res://assets/icons/settings_white_24dp.svg" id="9_mel13"]
|
[ext_resource type="Texture2D" uid="uid://dyh0ax51xqp8n" path="res://assets/icons/settings_white_24dp.svg" id="9_mel13"]
|
||||||
[ext_resource type="PackedScene" uid="uid://c01gkeldvjwtr" path="res://content/ui/menu/room/room_menu.tscn" id="10_u4i1x"]
|
[ext_resource type="PackedScene" uid="uid://c01gkeldvjwtr" path="res://content/ui/menu/room/room_menu.tscn" id="10_u4i1x"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://c6r4higceibif" path="res://content/ui/menu/settings/settings_menu.tscn" id="11_7wm6b"]
|
||||||
|
|
||||||
[sub_resource type="BoxMesh" id="BoxMesh_08du6"]
|
[sub_resource type="BoxMesh" id="BoxMesh_08du6"]
|
||||||
size = Vector3(0.3, 0.01, 0.3)
|
size = Vector3(0.3, 0.01, 0.3)
|
||||||
|
@ -84,3 +85,6 @@ texture = ExtResource("9_mel13")
|
||||||
[node name="EditMenu" parent="Content" instance=ExtResource("4_r2raj")]
|
[node name="EditMenu" parent="Content" instance=ExtResource("4_r2raj")]
|
||||||
|
|
||||||
[node name="RoomMenu" parent="Content" instance=ExtResource("10_u4i1x")]
|
[node name="RoomMenu" parent="Content" instance=ExtResource("10_u4i1x")]
|
||||||
|
|
||||||
|
[node name="SettingsMenu" parent="Content" instance=ExtResource("11_7wm6b")]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.01, 0)
|
||||||
|
|
|
@ -7,6 +7,7 @@ const wall_edge_scene = preload("res://content/ui/menu/room/wall_edge.tscn")
|
||||||
@onready var wall_corners = $TeleportRoot/WallCorners
|
@onready var wall_corners = $TeleportRoot/WallCorners
|
||||||
@onready var wall_edges = $TeleportRoot/WallEdges
|
@onready var wall_edges = $TeleportRoot/WallEdges
|
||||||
@onready var wall_mesh = $TeleportRoot/WallMesh
|
@onready var wall_mesh = $TeleportRoot/WallMesh
|
||||||
|
@onready var wall_collisions = $TeleportRoot/WallCollisions
|
||||||
@onready var toggle_edit_button = $Interface/ToggleEdit
|
@onready var toggle_edit_button = $Interface/ToggleEdit
|
||||||
|
|
||||||
var moving = null
|
var moving = null
|
||||||
|
@ -30,7 +31,17 @@ func _ready():
|
||||||
if edit_enabled == false:
|
if edit_enabled == false:
|
||||||
wall_corners.visible = false
|
wall_corners.visible = false
|
||||||
wall_edges.visible = false
|
wall_edges.visible = false
|
||||||
generate_mesh()
|
wall_mesh.mesh = generate_mesh()
|
||||||
|
var collisions = generate_collision(wall_mesh.mesh)
|
||||||
|
|
||||||
|
for old_coll in wall_collisions.get_children():
|
||||||
|
old_coll.queue_free()
|
||||||
|
|
||||||
|
for collision in collisions:
|
||||||
|
var static_body = StaticBody3D.new()
|
||||||
|
static_body.add_child(collision)
|
||||||
|
wall_collisions.add_child(static_body)
|
||||||
|
|
||||||
wall_mesh.visible = true
|
wall_mesh.visible = true
|
||||||
else:
|
else:
|
||||||
wall_corners.visible = true
|
wall_corners.visible = true
|
||||||
|
@ -67,7 +78,39 @@ func generate_mesh():
|
||||||
st.generate_tangents()
|
st.generate_tangents()
|
||||||
var mesh = st.commit()
|
var mesh = st.commit()
|
||||||
|
|
||||||
wall_mesh.mesh = mesh
|
return mesh
|
||||||
|
|
||||||
|
func generate_collision(mesh: ArrayMesh):
|
||||||
|
var corner_count = wall_corners.get_child_count()
|
||||||
|
|
||||||
|
if corner_count < 3:
|
||||||
|
return
|
||||||
|
|
||||||
|
var collision_shapes: Array[CollisionShape3D] = []
|
||||||
|
|
||||||
|
for i in range(corner_count):
|
||||||
|
var corner = get_corner(i)
|
||||||
|
var next_corner = get_corner(i + 1)
|
||||||
|
|
||||||
|
var shape = BoxShape3D.new()
|
||||||
|
shape.size = Vector3((next_corner.position - corner.position).length(), 3, 0.04)
|
||||||
|
|
||||||
|
var transform = Transform3D()
|
||||||
|
var back_vector = (corner.position - next_corner.position).cross(Vector3.UP).normalized() * shape.size.z / 2
|
||||||
|
|
||||||
|
transform.basis = Basis((next_corner.position - corner.position).normalized(), Vector3.UP, back_vector.normalized())
|
||||||
|
transform.origin = corner.position + (next_corner.position - corner.position) / 2 + back_vector + Vector3.UP * shape.size.y / 2
|
||||||
|
|
||||||
|
var collision_shape = CollisionShape3D.new()
|
||||||
|
|
||||||
|
collision_shape.shape = shape
|
||||||
|
collision_shape.transform = transform
|
||||||
|
|
||||||
|
collision_shapes.append(collision_shape)
|
||||||
|
|
||||||
|
print(collision_shapes)
|
||||||
|
|
||||||
|
return collision_shapes
|
||||||
|
|
||||||
func add_corner(position: Vector3):
|
func add_corner(position: Vector3):
|
||||||
var corner = wall_corner_scene.instantiate()
|
var corner = wall_corner_scene.instantiate()
|
||||||
|
|
|
@ -33,6 +33,8 @@ script = ExtResource("2_elugy")
|
||||||
material_override = ExtResource("3_fke3j")
|
material_override = ExtResource("3_fke3j")
|
||||||
mesh = SubResource("ArrayMesh_7dibq")
|
mesh = SubResource("ArrayMesh_7dibq")
|
||||||
|
|
||||||
|
[node name="WallCollisions" type="Node3D" parent="TeleportRoot"]
|
||||||
|
|
||||||
[node name="Background" type="MeshInstance3D" parent="."]
|
[node name="Background" type="MeshInstance3D" parent="."]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.15, 0, 0.15)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.15, 0, 0.15)
|
||||||
mesh = SubResource("BoxMesh_e37nn")
|
mesh = SubResource("BoxMesh_e37nn")
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:a84837d131d1a1676286c56bc80fc1dde59dc234ca68dc089b86d19c2aefc5a7
|
oid sha256:44ea33f724141838db4ace01175c71088af8994891a20c7fdc9bb3ac36dac9aa
|
||||||
size 101
|
size 160
|
||||||
|
|
17
content/ui/menu/settings/ball.tscn
Normal file
17
content/ui/menu/settings/ball.tscn
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
[gd_scene load_steps=3 format=3 uid="uid://cn3axur15ftft"]
|
||||||
|
|
||||||
|
[sub_resource type="SphereShape3D" id="SphereShape3D_orlq6"]
|
||||||
|
radius = 0.08
|
||||||
|
|
||||||
|
[sub_resource type="SphereMesh" id="SphereMesh_rfu32"]
|
||||||
|
radius = 0.08
|
||||||
|
height = 0.16
|
||||||
|
|
||||||
|
[node name="Ball" type="RigidBody3D"]
|
||||||
|
angular_damp = 39.224
|
||||||
|
|
||||||
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||||
|
shape = SubResource("SphereShape3D_orlq6")
|
||||||
|
|
||||||
|
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||||
|
mesh = SubResource("SphereMesh_rfu32")
|
15
content/ui/menu/settings/settings_menu.gd
Normal file
15
content/ui/menu/settings/settings_menu.gd
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
extends Node3D
|
||||||
|
|
||||||
|
const ball_scene = preload("res://content/ui/menu/settings/ball.tscn")
|
||||||
|
|
||||||
|
@onready var clickable = $Button/Clickable
|
||||||
|
@onready var balls = $Balls
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
clickable.on_click.connect(func(event):
|
||||||
|
var ball = ball_scene.instantiate()
|
||||||
|
ball.transform = event.controller.transform
|
||||||
|
ball.linear_velocity = -event.controller.transform.basis.z * 5 + Vector3(0, 5, 0)
|
||||||
|
get_tree().root.add_child(ball)
|
||||||
|
)
|
||||||
|
|
19
content/ui/menu/settings/settings_menu.tscn
Normal file
19
content/ui/menu/settings/settings_menu.tscn
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
[gd_scene load_steps=4 format=3 uid="uid://c6r4higceibif"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://content/ui/menu/settings/settings_menu.gd" id="1_0lte6"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="1_faxng"]
|
||||||
|
[ext_resource type="Script" path="res://content/functions/clickable.gd" id="3_qmg6q"]
|
||||||
|
|
||||||
|
[node name="SettingsMenu" type="Node3D"]
|
||||||
|
script = ExtResource("1_0lte6")
|
||||||
|
|
||||||
|
[node name="Button" parent="." instance=ExtResource("1_faxng")]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0458097, 0, 0.0435752)
|
||||||
|
|
||||||
|
[node name="Label3D" type="Label3D" parent="Button"]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0.138567, 0, 0)
|
||||||
|
pixel_size = 0.001
|
||||||
|
text = "Spawn Ball"
|
||||||
|
|
||||||
|
[node name="Clickable" type="Node" parent="Button"]
|
||||||
|
script = ExtResource("3_qmg6q")
|
Loading…
Reference in New Issue
Block a user