Fix collision shape of sensor entity

This commit is contained in:
Nitwel 2024-03-12 14:05:45 +01:00
parent 2a1207c513
commit f6d9828ad7
3 changed files with 22 additions and 9 deletions

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:1d0d7c19b4862ffa6c78a12151cbd01acb0f1f23400a7c75ad795680b61b6a1a oid sha256:26d5c6e9529db2b628074d05b9764878eaf60f35c6042f82944c2f12065766df
size 301 size 339

View File

@ -1,8 +1,9 @@
extends Entity extends Entity
const Entity = preload("../entity.gd") const Entity = preload ("../entity.gd")
@onready var label: Label3D = $Label @onready var label: Label3D = $Label
@onready var collision_shape = $CollisionShape3D
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
@ -21,7 +22,16 @@ func set_text(stateInfo):
if stateInfo["attributes"]["friendly_name"] != null: if stateInfo["attributes"]["friendly_name"] != null:
text = stateInfo["attributes"]["friendly_name"] + "\n" + text text = stateInfo["attributes"]["friendly_name"] + "\n" + text
if stateInfo["attributes"].has("unit_of_measurement") && stateInfo["attributes"]["unit_of_measurement"] != null: if stateInfo["attributes"].has("unit_of_measurement")&&stateInfo["attributes"]["unit_of_measurement"] != null:
text += " " + stateInfo["attributes"]["unit_of_measurement"] text += " " + stateInfo["attributes"]["unit_of_measurement"]
label.text = text label.text = text
var font = label.get_font()
var width = 0
var height = 0
var size = font.get_multiline_string_size(text, HORIZONTAL_ALIGNMENT_CENTER, label.width, label.font_size)
collision_shape.shape.size.x = size.x * label.pixel_size * 0.5
collision_shape.shape.size.y = size.y * label.pixel_size * 0.25

View File

@ -1,24 +1,27 @@
[gd_scene load_steps=5 format=3 uid="uid://xsiy71rsqulj"] [gd_scene load_steps=6 format=3 uid="uid://xsiy71rsqulj"]
[ext_resource type="Script" path="res://content/entities/sensor/sensor.gd" id="1_57ac8"] [ext_resource type="Script" path="res://content/entities/sensor/sensor.gd" id="1_57ac8"]
[ext_resource type="FontVariation" uid="uid://d2ofyimg5s65q" path="res://assets/fonts/ui_font_500.tres" id="2_4np3x"]
[ext_resource type="Script" path="res://content/functions/movable.gd" id="2_fpq5q"] [ext_resource type="Script" path="res://content/functions/movable.gd" id="2_fpq5q"]
[ext_resource type="Script" path="res://content/functions/occludable.gd" id="3_l3sp5"] [ext_resource type="Script" path="res://content/functions/occludable.gd" id="3_l3sp5"]
[sub_resource type="SphereShape3D" id="SphereShape3D_r20gc"] [sub_resource type="BoxShape3D" id="BoxShape3D_phuot"]
radius = 0.1 resource_local_to_scene = true
size = Vector3(0.18, 0.03, 0.02)
[node name="Sensor" type="StaticBody3D" groups=["entity"]] [node name="Sensor" type="StaticBody3D" groups=["entity"]]
collision_mask = 0 collision_mask = 0
script = ExtResource("1_57ac8") script = ExtResource("1_57ac8")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."] [node name="CollisionShape3D" type="CollisionShape3D" parent="."]
shape = SubResource("SphereShape3D_r20gc") shape = SubResource("BoxShape3D_phuot")
[node name="Label" type="Label3D" parent="."] [node name="Label" type="Label3D" parent="."]
transform = Transform3D(0.4, 0, 0, 0, 0.4, 0, 0, 0, 0.4, 0, 0, 0) transform = Transform3D(0.4, 0, 0, 0, 0.4, 0, 0, 0, 0.4, 0, 0, 0)
pixel_size = 0.001 pixel_size = 0.001
text = "some text text = "some text
" "
font = ExtResource("2_4np3x")
font_size = 80 font_size = 80
[node name="Movable" type="Node" parent="."] [node name="Movable" type="Node" parent="."]