spawner can now spawn 3d models
This commit is contained in:
parent
ccd3ef577c
commit
f025f89401
10 changed files with 59 additions and 34 deletions
|
|
@ -1,13 +1,15 @@
|
||||||
[gd_resource type="Resource" script_class="MonsterStats" load_steps=3 format=3 uid="uid://ym438vedcdyl"]
|
[gd_resource type="Resource" script_class="MonsterStats" load_steps=4 format=3 uid="uid://ym438vedcdyl"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://resources/monster.gd" id="1_47qp4"]
|
[ext_resource type="PackedScene" uid="uid://h2we7rb772hy" path="res://assets/models/round_bat/model/bat.glb" id="1_ajl37"]
|
||||||
[ext_resource type="Texture2D" uid="uid://b6ylra30qxf30" path="res://assets/logo/logo.png" id="2_8r754"]
|
[ext_resource type="Texture2D" uid="uid://b6ylra30qxf30" path="res://assets/logo/logo.png" id="2_8r754"]
|
||||||
|
[ext_resource type="Script" path="res://resources/monster_stats.gd" id="2_ec3n5"]
|
||||||
|
|
||||||
[resource]
|
[resource]
|
||||||
script = ExtResource("1_47qp4")
|
script = ExtResource("2_ec3n5")
|
||||||
thumbnail = ExtResource("2_8r754")
|
thumbnail = ExtResource("2_8r754")
|
||||||
name = "Debug Monster 1"
|
name = "Debug Monster 1"
|
||||||
health = 110
|
health = 110
|
||||||
attack_value = 12
|
attack_value = 12
|
||||||
defense_value = 15
|
defense_value = 15
|
||||||
speed_value = 8
|
speed_value = 8
|
||||||
|
model = ExtResource("1_ajl37")
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[gd_resource type="Resource" script_class="MonsterStats" load_steps=3 format=3 uid="uid://br8opay3hdptg"]
|
[gd_resource type="Resource" script_class="MonsterStats" load_steps=3 format=3 uid="uid://br8opay3hdptg"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://resources/monster.gd" id="1_saexp"]
|
[ext_resource type="Script" path="res://resources/monster_stats.gd" id="1_saexp"]
|
||||||
[ext_resource type="Texture2D" uid="uid://b6ylra30qxf30" path="res://assets/logo/logo.png" id="2_3x4e0"]
|
[ext_resource type="Texture2D" uid="uid://b6ylra30qxf30" path="res://assets/logo/logo.png" id="2_3x4e0"]
|
||||||
|
|
||||||
[resource]
|
[resource]
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[gd_resource type="Resource" script_class="MonsterStats" load_steps=3 format=3 uid="uid://y250cwuiq5y"]
|
[gd_resource type="Resource" script_class="MonsterStats" load_steps=3 format=3 uid="uid://y250cwuiq5y"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://resources/monster.gd" id="1_eka2r"]
|
[ext_resource type="Script" path="res://resources/monster_stats.gd" id="1_eka2r"]
|
||||||
[ext_resource type="Texture2D" uid="uid://b6ylra30qxf30" path="res://assets/logo/logo.png" id="2_b7c7s"]
|
[ext_resource type="Texture2D" uid="uid://b6ylra30qxf30" path="res://assets/logo/logo.png" id="2_b7c7s"]
|
||||||
|
|
||||||
[resource]
|
[resource]
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ extends Resource
|
||||||
@export var attack_value: int = 10
|
@export var attack_value: int = 10
|
||||||
@export var defense_value: int = 10
|
@export var defense_value: int = 10
|
||||||
@export var speed_value: int = 10
|
@export var speed_value: int = 10
|
||||||
|
@export var model: PackedScene
|
||||||
|
|
||||||
func _init() -> void:
|
func _init() -> void:
|
||||||
pass
|
pass
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
[gd_scene load_steps=14 format=3 uid="uid://p8agd0dfam0p"]
|
[gd_scene load_steps=15 format=3 uid="uid://p8agd0dfam0p"]
|
||||||
|
|
||||||
[ext_resource type="PackedScene" uid="uid://be5bc5gjbo875" path="res://scenes/player.tscn" id="1_ra6oo"]
|
[ext_resource type="PackedScene" uid="uid://be5bc5gjbo875" path="res://scenes/player.tscn" id="1_ra6oo"]
|
||||||
[ext_resource type="PackedScene" uid="uid://tyjgdu65yj3m" path="res://assets/models/round_bat/round_bat_skin.tscn" id="2_lks2w"]
|
[ext_resource type="PackedScene" uid="uid://tyjgdu65yj3m" path="res://assets/models/round_bat/round_bat_skin.tscn" id="2_lks2w"]
|
||||||
[ext_resource type="PackedScene" uid="uid://dawpmu4vvv3rs" path="res://scenes/monster_spawnpoint.tscn" id="3_esgto"]
|
[ext_resource type="PackedScene" uid="uid://dawpmu4vvv3rs" path="res://scenes/monster_spawnpoint.tscn" id="3_esgto"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://cytaswycabcel" path="res://scenes/monster.tscn" id="4_bpsqy"]
|
||||||
|
|
||||||
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_g80j5"]
|
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_g80j5"]
|
||||||
sky_horizon_color = Color(0.64625, 0.65575, 0.67075, 1)
|
sky_horizon_color = Color(0.64625, 0.65575, 0.67075, 1)
|
||||||
|
|
@ -87,3 +88,4 @@ script = null
|
||||||
|
|
||||||
[node name="MonsterSpawnpoint" parent="." instance=ExtResource("3_esgto")]
|
[node name="MonsterSpawnpoint" parent="." instance=ExtResource("3_esgto")]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -6, 0, -10)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -6, 0, -10)
|
||||||
|
spawnable_monsters = Array[PackedScene]([ExtResource("4_bpsqy")])
|
||||||
|
|
|
||||||
8
scenes/monster.tscn
Normal file
8
scenes/monster.tscn
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
[gd_scene load_steps=3 format=3 uid="uid://cytaswycabcel"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://scripts/monster.gd" id="1_13xtk"]
|
||||||
|
[ext_resource type="Resource" uid="uid://ym438vedcdyl" path="res://resources/DebugMonster1.tres" id="2_rjclr"]
|
||||||
|
|
||||||
|
[node name="Monster" type="Node3D"]
|
||||||
|
script = ExtResource("1_13xtk")
|
||||||
|
monster_stats = ExtResource("2_rjclr")
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
[gd_scene load_steps=6 format=3 uid="uid://dawpmu4vvv3rs"]
|
[gd_scene load_steps=6 format=3 uid="uid://dawpmu4vvv3rs"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://scripts/monster_spawnpoint.gd" id="1_eyon3"]
|
[ext_resource type="Script" path="res://scripts/monster_spawnpoint.gd" id="1_eyon3"]
|
||||||
[ext_resource type="Script" path="res://resources/monster.gd" id="2_u38vv"]
|
[ext_resource type="Script" path="res://resources/monster_stats.gd" id="2_u38vv"]
|
||||||
[ext_resource type="Resource" uid="uid://ym438vedcdyl" path="res://resources/DebugMonster1.tres" id="3_4axng"]
|
[ext_resource type="Resource" uid="uid://ym438vedcdyl" path="res://resources/DebugMonster1.tres" id="3_4axng"]
|
||||||
|
|
||||||
[sub_resource type="SphereMesh" id="SphereMesh_phb77"]
|
[sub_resource type="SphereMesh" id="SphereMesh_phb77"]
|
||||||
|
|
|
||||||
|
|
@ -1,38 +1,40 @@
|
||||||
extends Control
|
extends Control
|
||||||
|
|
||||||
var touch_start: Vector2 = Vector2(0, 0)
|
|
||||||
var pressed: bool = false
|
var pressed: bool = false
|
||||||
var previous_position: Vector2 = Vector2(0,0)
|
var previous_position: Vector2 = Vector2(0, 0)
|
||||||
var touch_delta: Vector2 = Vector2(0, 0)
|
var touch_delta: Vector2 = Vector2(0, 0)
|
||||||
var current_delta: Vector2 = Vector2()
|
var current_delta: Vector2 = Vector2(0, 0)
|
||||||
var dampening_factor: float = 0.1 # Lower values = more dampening (0-1 range)
|
var dampening_factor: float = 0.8 # Lower values = more dampening (0-1 range)
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
current_delta = lerp(current_delta, Vector2(0, 0), dampening_factor)
|
var t = clamp(dampening_factor * delta, 0.0, 1.0) # Clamp to 0-1 range
|
||||||
print(current_delta)
|
current_delta = lerp(current_delta, Vector2(0, 0), ease(t, -0.5)) # Use easing with lerp
|
||||||
|
|
||||||
|
# Simulate joystick motion using the dampened delta.
|
||||||
simulate_joystick_motion(JOY_AXIS_RIGHT_X, -current_delta.x * 0.1, 0)
|
simulate_joystick_motion(JOY_AXIS_RIGHT_X, -current_delta.x * 0.1, 0)
|
||||||
|
|
||||||
|
# Debug: See the current delta
|
||||||
|
#print(current_delta)
|
||||||
|
|
||||||
func _on_gui_input(event: InputEvent) -> void:
|
func _on_gui_input(event: InputEvent) -> void:
|
||||||
|
# Filter touch or drag events only.
|
||||||
if event is not InputEventScreenTouch and event is not InputEventScreenDrag:
|
if event is not InputEventScreenTouch and event is not InputEventScreenDrag:
|
||||||
return
|
return
|
||||||
|
|
||||||
if event is InputEventScreenTouch and pressed == false and event.is_pressed() == true:
|
if event is InputEventScreenTouch:
|
||||||
|
if event.is_pressed():
|
||||||
pressed = true
|
pressed = true
|
||||||
touch_start = event.position
|
previous_position = event.position # Initialize previous position on touch start
|
||||||
#print("touch start")
|
else:
|
||||||
|
|
||||||
if event is InputEventScreenTouch and pressed == true and event.is_pressed() == false:
|
|
||||||
pressed = false
|
pressed = false
|
||||||
#simulate_joystick_motion(JOY_AXIS_RIGHT_X, 0, 0)
|
touch_delta = Vector2(0, 0) # Reset delta on touch release
|
||||||
#print("touch end")
|
|
||||||
|
|
||||||
if pressed and event is InputEventScreenDrag:
|
if pressed and event is InputEventScreenDrag:
|
||||||
|
# Calculate the delta between the current and previous touch position.
|
||||||
touch_delta = event.position - previous_position
|
touch_delta = event.position - previous_position
|
||||||
|
|
||||||
current_delta = touch_delta #lerp(current_delta, touch_delta, 1.0 - dampening_factor)
|
|
||||||
|
|
||||||
previous_position = event.position
|
previous_position = event.position
|
||||||
|
current_delta = touch_delta * 0.5 # Update current delta with the new drag value
|
||||||
|
|
||||||
func simulate_joystick_motion(axis: int, value: float, device_id: int = 0) -> void:
|
func simulate_joystick_motion(axis: int, value: float, device_id: int = 0) -> void:
|
||||||
var joystick_event = InputEventJoypadMotion.new()
|
var joystick_event = InputEventJoypadMotion.new()
|
||||||
|
|
|
||||||
13
scripts/monster.gd
Normal file
13
scripts/monster.gd
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
class_name Monster
|
||||||
|
extends Node3D
|
||||||
|
|
||||||
|
@export var monster_stats: MonsterStats
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready() -> void:
|
||||||
|
var model_instance = monster_stats.model.instantiate()
|
||||||
|
add_child(model_instance)
|
||||||
|
|
||||||
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
|
func _process(delta: float) -> void:
|
||||||
|
pass
|
||||||
|
|
@ -8,7 +8,7 @@ extends Node3D
|
||||||
@onready var spawn_timer: Timer = Timer.new()
|
@onready var spawn_timer: Timer = Timer.new()
|
||||||
|
|
||||||
# list that holds all spawnable monsters
|
# list that holds all spawnable monsters
|
||||||
@export var spawnable_monsters: Array[MonsterStats]
|
@export var spawnable_monsters: Array[PackedScene]
|
||||||
|
|
||||||
# the maximum amount of spawned monsters
|
# the maximum amount of spawned monsters
|
||||||
# no monsters will spawn, when this number is reached
|
# no monsters will spawn, when this number is reached
|
||||||
|
|
@ -48,17 +48,14 @@ func spawn() -> void:
|
||||||
var spawn_point_z = randf_range(-max_distance_spawn, max_distance_spawn)
|
var spawn_point_z = randf_range(-max_distance_spawn, max_distance_spawn)
|
||||||
|
|
||||||
# instantiate a monster .tscn scene
|
# instantiate a monster .tscn scene
|
||||||
var monster_to_spawn = spawnable_monsters[0]
|
var monster_to_spawn = spawnable_monsters[0].instantiate()
|
||||||
|
|
||||||
# TODO: Replace this with actual instantiation of a walking monster
|
|
||||||
var mesh_instance = MeshInstance3D.new()
|
|
||||||
mesh_instance.mesh = BoxMesh.new()
|
|
||||||
# calculate the position of the monster and add the offset of the spawnpoint itself
|
# calculate the position of the monster and add the offset of the spawnpoint itself
|
||||||
var monster_position = Vector3(spawn_point_x, 0.2, spawn_point_z)
|
var monster_position = Vector3(spawn_point_x, 0.2, spawn_point_z)
|
||||||
mesh_instance.position = monster_position + position
|
monster_to_spawn.position = monster_position + position
|
||||||
|
|
||||||
var debug_level_node = get_node("/root/Main/CurrentLevel/DebugLevel")
|
var debug_level_node = get_node("/root/Main/CurrentLevel/DebugLevel")
|
||||||
debug_level_node.add_child(mesh_instance)
|
debug_level_node.add_child(monster_to_spawn)
|
||||||
print("spawning mob")
|
print("spawning mob")
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue