restructured folders
This commit is contained in:
parent
e3aec75404
commit
0f5045dc22
22 changed files with 32 additions and 21 deletions
54
entities/monster/monster.gd
Normal file
54
entities/monster/monster.gd
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
class_name Monster
|
||||
extends CharacterBody3D
|
||||
|
||||
signal level_up
|
||||
|
||||
@export var stats: MonsterData = MonsterData.new()
|
||||
|
||||
var spawn_point: Vector3 = Vector3(0, 0, 0)
|
||||
|
||||
# DEBUG MOVEMENT
|
||||
@onready var time: float = 16.0
|
||||
@onready var frequency: float = 1.0
|
||||
@onready var amplitude: float = 0.5
|
||||
var in_battle: bool = false
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
var model_instance = stats.model.instantiate()
|
||||
frequency = randf_range(1.0, 4.0)
|
||||
amplitude = randf_range(1.0, 6.0)
|
||||
spawn_point = position
|
||||
add_child(model_instance)
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if in_battle:
|
||||
velocity = Vector3.ZERO
|
||||
return
|
||||
|
||||
time += delta
|
||||
var x_movement = sin(time * frequency) * amplitude
|
||||
var z_movement = cos(time * frequency) * amplitude
|
||||
velocity = Vector3(x_movement, 0, z_movement)
|
||||
|
||||
# if move_and_slide reports collisions
|
||||
if move_and_slide():
|
||||
var collision = get_slide_collision(0)
|
||||
var collider = collision.get_collider()
|
||||
|
||||
# if the monster collided with the player...
|
||||
if collider.name == "Player":
|
||||
velocity = Vector3.ZERO
|
||||
in_battle = true
|
||||
|
||||
# calculate players new position
|
||||
# from the camera 3 units backwards
|
||||
var camera = collider.find_child("Camera3D")
|
||||
|
||||
# local z axis of the camera
|
||||
var local_z = camera.global_transform.basis.z
|
||||
|
||||
var new_player_position = camera.global_transform.origin + local_z * 3
|
||||
|
||||
collider.start_battle(self, new_player_position)
|
||||
#rotate_toward(rotation.z, collider.rotation.z, 1.0)
|
||||
22
entities/monster/monster.tscn
Normal file
22
entities/monster/monster.tscn
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
[gd_scene load_steps=5 format=3 uid="uid://cytaswycabcel"]
|
||||
|
||||
[ext_resource type="Script" path="res://entities/monster/monster.gd" id="1_5gfkg"]
|
||||
[ext_resource type="Material" uid="uid://ctul3e67rcq23" path="res://materials/CollisionDebugMaterial.tres" id="2_bf2kb"]
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_tjvna"]
|
||||
radius = 0.4
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_aou7a"]
|
||||
radius = 0.4
|
||||
height = 0.8
|
||||
|
||||
[node name="Monster" type="CharacterBody3D"]
|
||||
script = ExtResource("1_5gfkg")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("SphereShape3D_tjvna")
|
||||
|
||||
[node name="CollisionVisualizer" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("SphereMesh_aou7a")
|
||||
skeleton = NodePath("")
|
||||
surface_material_override/0 = ExtResource("2_bf2kb")
|
||||
Loading…
Add table
Add a link
Reference in a new issue