nameLabels now always face the camera
This commit is contained in:
parent
686e2e9159
commit
c9fc172fc1
3 changed files with 24 additions and 2 deletions
|
@ -27,8 +27,8 @@ var runnerDead = false
|
||||||
func _ready():
|
func _ready():
|
||||||
name = str(teddyAuthority)
|
name = str(teddyAuthority)
|
||||||
Global.playingGame = true
|
Global.playingGame = true
|
||||||
Global.selfTeddy = selfTeddy
|
|
||||||
selfTeddy = self.get_path()
|
selfTeddy = self.get_path()
|
||||||
|
Global.selfTeddy = selfTeddy
|
||||||
selfTeddyNode = get_node(selfTeddy)
|
selfTeddyNode = get_node(selfTeddy)
|
||||||
teddyCollider = str(self.get_path()) + '/CollisionShape3D'
|
teddyCollider = str(self.get_path()) + '/CollisionShape3D'
|
||||||
teddyName = str(self.get_path()) + '/nameLabel'
|
teddyName = str(self.get_path()) + '/nameLabel'
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
[gd_scene load_steps=5 format=3 uid="uid://dp1q51kvd8uow"]
|
[gd_scene load_steps=6 format=3 uid="uid://dp1q51kvd8uow"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://characters/teddy/Teddy.gd" id="1_ywxo5"]
|
[ext_resource type="Script" path="res://characters/teddy/Teddy.gd" id="1_ywxo5"]
|
||||||
[ext_resource type="PackedScene" uid="uid://b3l10agcjfgdx" path="res://characters/teddy/model_glb/teddy.glb" id="2_xx41h"]
|
[ext_resource type="PackedScene" uid="uid://b3l10agcjfgdx" path="res://characters/teddy/model_glb/teddy.glb" id="2_xx41h"]
|
||||||
|
[ext_resource type="Script" path="res://scripts/nameLabel.gd" id="3_1v4js"]
|
||||||
|
|
||||||
[sub_resource type="BoxShape3D" id="BoxShape3D_rpt2n"]
|
[sub_resource type="BoxShape3D" id="BoxShape3D_rpt2n"]
|
||||||
size = Vector3(1, 1.99126, 1)
|
size = Vector3(1, 1.99126, 1)
|
||||||
|
@ -36,3 +37,4 @@ transform = Transform3D(-0.33293, 1.16122e-16, -2.91057e-08, 1.16122e-16, 0.3329
|
||||||
[node name="nameLabel" type="Label3D" parent="."]
|
[node name="nameLabel" type="Label3D" parent="."]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.60152, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.60152, 0)
|
||||||
text = "Un-named Player"
|
text = "Un-named Player"
|
||||||
|
script = ExtResource("3_1v4js")
|
||||||
|
|
20
scripts/nameLabel.gd
Normal file
20
scripts/nameLabel.gd
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
extends Label3D
|
||||||
|
|
||||||
|
var campath = "/CollisionShape3D/Neck/Camera3D"
|
||||||
|
var labelpath = "/nameLabel"
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready():
|
||||||
|
pass # Replace with function body.
|
||||||
|
|
||||||
|
|
||||||
|
func _process(delta):
|
||||||
|
var cam_node = get_node(str(Global.selfTeddy) + campath)
|
||||||
|
var self_label = get_node(str(Global.selfTeddy) + labelpath)
|
||||||
|
var camera_position = cam_node.global_transform.origin
|
||||||
|
var direction = (camera_position - global_transform.origin).normalized()
|
||||||
|
var flipped_direction = -direction
|
||||||
|
var target_pos = global_transform.origin + flipped_direction + Vector3(0.01, 0.01, 0.01)
|
||||||
|
|
||||||
|
# Set the label's rotation to face the camera
|
||||||
|
look_at(target_pos, Vector3(0, 1, 0))
|
Loading…
Reference in a new issue