add projectiles
This commit is contained in:
parent
d53fe046a8
commit
cd7bc7a82f
15
resources/materials/debug/debug_projectile.tres
Normal file
15
resources/materials/debug/debug_projectile.tres
Normal file
@ -0,0 +1,15 @@
|
||||
[gd_resource type="StandardMaterial3D" load_steps=3 format=3 uid="uid://cux40v5s5sok3"]
|
||||
|
||||
[ext_resource type="Shader" path="res://shaders/wireframe.gdshader" id="1_8koui"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_ionb4"]
|
||||
render_priority = 0
|
||||
shader = ExtResource("1_8koui")
|
||||
shader_parameter/albedo = Color(1, 0, 1, 1)
|
||||
shader_parameter/outline_width = 0.0
|
||||
|
||||
[resource]
|
||||
next_pass = SubResource("ShaderMaterial_ionb4")
|
||||
transparency = 1
|
||||
shading_mode = 0
|
||||
albedo_color = Color(1, 0, 1, 0.435294)
|
||||
29
scenes/enemies/projectile_spawner.tscn
Normal file
29
scenes/enemies/projectile_spawner.tscn
Normal file
@ -0,0 +1,29 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://cksoaevb5sloo"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/enemies/projectile_spawner.gd" id="1_fdaky"]
|
||||
[ext_resource type="PackedScene" uid="uid://cejn8wfgw14xs" path="res://scenes/projectiles/projectile.tscn" id="2_p0btw"]
|
||||
|
||||
[sub_resource type="BoxMesh" id="BoxMesh_860q6"]
|
||||
|
||||
[sub_resource type="CylinderMesh" id="CylinderMesh_esok8"]
|
||||
top_radius = 0.25
|
||||
bottom_radius = 0.25
|
||||
height = 0.635
|
||||
|
||||
[node name="ProjectileSpawner" type="Node3D" node_paths=PackedStringArray("_spawn_point")]
|
||||
script = ExtResource("1_fdaky")
|
||||
_spawn_point = NodePath("Marker3D")
|
||||
_projectile_scene = ExtResource("2_p0btw")
|
||||
_velocity = Vector3(0, 0, -5)
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
|
||||
mesh = SubResource("BoxMesh_860q6")
|
||||
|
||||
[node name="MeshInstance3D2" type="MeshInstance3D" parent="MeshInstance3D"]
|
||||
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, -0.339801)
|
||||
mesh = SubResource("CylinderMesh_esok8")
|
||||
skeleton = NodePath("../..")
|
||||
|
||||
[node name="Marker3D" type="Marker3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.624811, -0.590804)
|
||||
24
scenes/projectiles/projectile.tscn
Normal file
24
scenes/projectiles/projectile.tscn
Normal file
@ -0,0 +1,24 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://cejn8wfgw14xs"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/projectiles/projectile.gd" id="1_kv6x5"]
|
||||
[ext_resource type="Material" uid="uid://cux40v5s5sok3" path="res://resources/materials/debug/debug_projectile.tres" id="2_b024o"]
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_vc8th"]
|
||||
radius = 0.25
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_ctqwx"]
|
||||
radius = 0.25
|
||||
height = 0.5
|
||||
|
||||
[node name="Projectile" type="Area3D"]
|
||||
top_level = true
|
||||
collision_layer = 32
|
||||
collision_mask = 32
|
||||
script = ExtResource("1_kv6x5")
|
||||
_collision_debug_material = ExtResource("2_b024o")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("SphereShape3D_vc8th")
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("SphereMesh_ctqwx")
|
||||
@ -1,8 +1,9 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://c0buetf2h266d"]
|
||||
[gd_scene load_steps=6 format=3 uid="uid://c0buetf2h266d"]
|
||||
|
||||
[ext_resource type="Material" uid="uid://btpy4dp5lb8il" path="res://resources/materials/test_triplanar.tres" id="1_ixaua"]
|
||||
[ext_resource type="PackedScene" uid="uid://b73y71y3efmv" path="res://scenes/player.tscn" id="2_f4ehn"]
|
||||
[ext_resource type="Script" path="res://scripts/main_camera.gd" id="3_f4hhh"]
|
||||
[ext_resource type="PackedScene" uid="uid://cksoaevb5sloo" path="res://scenes/enemies/projectile_spawner.tscn" id="4_84n74"]
|
||||
|
||||
[sub_resource type="Environment" id="Environment_wctar"]
|
||||
|
||||
@ -40,3 +41,6 @@ current = true
|
||||
fov = 20.0
|
||||
near = 35.0
|
||||
script = ExtResource("3_f4hhh")
|
||||
|
||||
[node name="ProjectileSpawner" parent="." instance=ExtResource("4_84n74")]
|
||||
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 9.97514, 0, -7.30423)
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
class_name DebugCollisionShapes
|
||||
extends RefCounted
|
||||
|
||||
const MARGIN = 0.01
|
||||
|
||||
var _mesh_nodes: Array[MeshInstance3D] = []
|
||||
|
||||
|
||||
@ -21,32 +23,32 @@ func init(children: Array[Node], parent: Node, material: Material) -> void:
|
||||
if shape_node.shape is CapsuleShape3D:
|
||||
var shape := shape_node.shape as CapsuleShape3D
|
||||
var mesh := CapsuleMesh.new()
|
||||
mesh.radius = shape.radius
|
||||
mesh.height = shape.height
|
||||
mesh.radius = shape.radius + MARGIN
|
||||
mesh.height = shape.height + MARGIN
|
||||
mesh.radial_segments = 8
|
||||
mesh.rings = 1
|
||||
mesh_node.mesh = mesh
|
||||
if shape_node.shape is SphereShape3D:
|
||||
var shape := shape_node.shape as SphereShape3D
|
||||
var mesh := SphereMesh.new()
|
||||
mesh.radius = shape.radius
|
||||
mesh.height = shape.radius * 2
|
||||
mesh.radius = shape.radius + MARGIN
|
||||
mesh.height = shape.radius * 2 + MARGIN
|
||||
mesh.radial_segments = 8
|
||||
mesh.rings = 4
|
||||
mesh_node.mesh = mesh
|
||||
if shape_node.shape is CylinderShape3D:
|
||||
var shape := shape_node.shape as CylinderShape3D
|
||||
var mesh := CylinderMesh.new()
|
||||
mesh.top_radius = shape.radius
|
||||
mesh.bottom_radius = shape.radius
|
||||
mesh.height = shape.height
|
||||
mesh.top_radius = shape.radius + MARGIN
|
||||
mesh.bottom_radius = shape.radius + MARGIN
|
||||
mesh.height = shape.height + MARGIN
|
||||
mesh.radial_segments = 8
|
||||
mesh.rings = 0
|
||||
mesh_node.mesh = mesh
|
||||
|
||||
mesh_node.material_override = material
|
||||
mesh_node.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
|
||||
mesh_node.visible = false
|
||||
mesh_node.visible = Debugger.mode == Debugger.Mode.FULL
|
||||
parent.add_child(mesh_node)
|
||||
mesh_node.global_transform = (child as Node3D).global_transform
|
||||
_mesh_nodes.append(mesh_node)
|
||||
|
||||
22
scripts/enemies/projectile_spawner.gd
Normal file
22
scripts/enemies/projectile_spawner.gd
Normal file
@ -0,0 +1,22 @@
|
||||
extends Node3D
|
||||
|
||||
@export var _spawn_point: Node3D
|
||||
@export var _projectile_scene: PackedScene
|
||||
@export var _velocity: Vector3 = Vector3.FORWARD
|
||||
@export var _spawn_rate: float = 2
|
||||
|
||||
var _spawn_timer: float
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_spawn_timer = _spawn_rate
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if _spawn_timer <= 0:
|
||||
_spawn_timer = _spawn_rate
|
||||
var projectile := _projectile_scene.instantiate() as Projectile
|
||||
projectile.init(basis * _velocity, _spawn_point.global_position)
|
||||
add_child(projectile)
|
||||
|
||||
_spawn_timer -= delta
|
||||
32
scripts/projectiles/projectile.gd
Normal file
32
scripts/projectiles/projectile.gd
Normal file
@ -0,0 +1,32 @@
|
||||
class_name Projectile
|
||||
extends Area3D
|
||||
|
||||
@export var _collision_debug_material: Material
|
||||
|
||||
var _start_position: Vector3
|
||||
var _velocity: Vector3
|
||||
var _lifetime: float
|
||||
|
||||
var _life_timer: float
|
||||
|
||||
var _debug_collision_shapes := DebugCollisionShapes.new()
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_life_timer = _lifetime
|
||||
_debug_collision_shapes.init(get_children(), self, _collision_debug_material)
|
||||
global_position = _start_position
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if _life_timer <= 0:
|
||||
queue_free()
|
||||
|
||||
_life_timer -= delta
|
||||
global_position += _velocity * delta
|
||||
|
||||
|
||||
func init(velocity: Vector3, start_position: Vector3, lifetime: float = 10) -> void:
|
||||
_velocity = velocity
|
||||
_start_position = start_position
|
||||
_lifetime = lifetime
|
||||
Loading…
Reference in New Issue
Block a user