set rotation from spawn point

This commit is contained in:
veclav talica 2024-08-02 05:12:13 +03:00
parent a361350ec2
commit b4faa5d35b
6 changed files with 19 additions and 9 deletions

View File

@ -2,7 +2,7 @@
[ext_resource type="Script" path="res://Scripts/Main.gd" id="1_2yjjx"] [ext_resource type="Script" path="res://Scripts/Main.gd" id="1_2yjjx"]
[ext_resource type="PackedScene" uid="uid://deff7lt34nj0h" path="res://Spaces/Dungeon.tscn" id="2_4gs22"] [ext_resource type="PackedScene" uid="uid://deff7lt34nj0h" path="res://Spaces/Dungeon.tscn" id="2_4gs22"]
[ext_resource type="PackedScene" uid="uid://b83k3b5x1wmyl" path="res://Scenes/Player.tscn" id="3_eq7hn"] [ext_resource type="PackedScene" uid="uid://d3e3a6xdwo2dp" path="res://Scenes/Player.tscn" id="3_eq7hn"]
[sub_resource type="Environment" id="Environment_pn2uj"] [sub_resource type="Environment" id="Environment_pn2uj"]

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=2 format=3 uid="uid://b83k3b5x1wmyl"] [gd_scene load_steps=2 format=3 uid="uid://d3e3a6xdwo2dp"]
[ext_resource type="Script" path="res://Scripts/Player.gd" id="1_m1g7d"] [ext_resource type="Script" path="res://Scripts/Player.gd" id="1_m1g7d"]

View File

@ -3,8 +3,10 @@ extends Node3D
func _ready(): func _ready():
add_child($Dungeon.generate_geometry()) add_child($Dungeon.generate_geometry())
$Player.position = $Dungeon.get_spawn_point() var spawn = $Dungeon.get_spawn()
$Player.position = spawn.position
$Player.position.y += 0.5 $Player.position.y += 0.5
$Player.rotation = spawn.rotation
func _process(delta): func _process(delta):

View File

@ -21,14 +21,14 @@ func generate_geometry() -> Node3D:
return root return root
func get_spawn_point() -> Vector3: func get_spawn() -> SpaceSpawn.Desc:
var stack := [self] var stack := [self]
while stack: while stack:
var node = stack.pop_front() var node = stack.pop_front()
for child in node.get_children(): for child in node.get_children():
if child is SpaceSpawn: if child is SpaceSpawn:
return child.space_position(self) return child.get_spawn_desc(self)
stack.push_back(child) stack.push_back(child)
return Vector3.ZERO return null

View File

@ -5,6 +5,14 @@ extends SpaceEntity
class_name SpaceSpawn class_name SpaceSpawn
func space_position(space: Space) -> Vector3: class Desc extends RefCounted:
var position: Vector3
var rotation: Vector3
func get_spawn_desc(space: Space) -> Desc:
# todo: Get current region elevation # todo: Get current region elevation
return Vector3(global_position.x * space.unit_scale, 0, global_position.y * space.unit_scale) var desc := Desc.new()
desc.position = Vector3(global_position.x * space.unit_scale, 0, global_position.y * space.unit_scale)
desc.rotation.y = rotation_degrees
return desc

View File

@ -31,7 +31,7 @@ wall_texture = ExtResource("3_ondo6")
[node name="Spawn" type="Sprite2D" parent="Room"] [node name="Spawn" type="Sprite2D" parent="Room"]
position = Vector2(-48, 32) position = Vector2(-48, 32)
rotation = 0.159622 rotation = 1.83259
scale = Vector2(0.25, 0.25) scale = Vector2(0.25, 0.25)
texture = ExtResource("3_7vff1") texture = ExtResource("3_7vff1")
script = ExtResource("4_rhl23") script = ExtResource("4_rhl23")