Implement monke spawner

This commit is contained in:
Atirut Wattanamongkol 2022-11-20 04:07:41 +07:00
parent 047c134e74
commit 70af89a79e
3 changed files with 15 additions and 1 deletions

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=3 format=3 uid="uid://q5y0ct8qdw8e"] [gd_scene load_steps=3 format=3 uid="uid://b6xiqhe5i8bej"]
[ext_resource type="ArrayMesh" uid="uid://v58ypl1tockm" path="res://meshes/suzanne.obj" id="1_r4k80"] [ext_resource type="ArrayMesh" uid="uid://v58ypl1tockm" path="res://meshes/suzanne.obj" id="1_r4k80"]

View file

@ -2,6 +2,7 @@ extends Node
@onready var world := Node3D.new() @onready var world := Node3D.new()
var suzanne := preload("res://prefabs/suzanne.tscn")
func _ready() -> void: func _ready() -> void:
@ -23,3 +24,11 @@ func _ready() -> void:
await get_tree().physics_frame await get_tree().physics_frame
print("Map load completed in %f seconds" % ((Time.get_ticks_msec() - start_t) / 1000)) print("Map load completed in %f seconds" % ((Time.get_ticks_msec() - start_t) / 1000))
add_child(world) add_child(world)
func _unhandled_input(event: InputEvent) -> void:
if event is InputEventKey:
if event.physical_keycode == KEY_SPACE and event.pressed:
var node := suzanne.instantiate() as RigidBody3D
add_child(node)
node.global_position = get_viewport().get_camera_3d().global_position

View file

@ -59,4 +59,9 @@ offset_right = 222.0
offset_bottom = 28.0 offset_bottom = 28.0
text = "Map loader test" text = "Map loader test"
[node name="Label" type="Label" parent="GUI"]
offset_right = 40.0
offset_bottom = 23.0
text = "Press space to spawn Suzanne"
[node name="flycam" parent="." instance=ExtResource("3_850h8")] [node name="flycam" parent="." instance=ExtResource("3_850h8")]