Preliminary lasers

This commit is contained in:
Marco 2025-10-09 09:11:25 +02:00
commit 7cb5bfb593
20 changed files with 1779 additions and 1049 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -15,9 +15,11 @@ dest_files=["res://.godot/imported/Floor_Emitter.gltf-1cce213213ebe4efb5932c1347
nodes/root_type=""
nodes/root_name=""
nodes/root_script=null
nodes/apply_root_scale=true
nodes/root_scale=1.0
nodes/import_as_skeleton_bones=false
nodes/use_name_suffixes=true
nodes/use_node_type_suffixes=true
meshes/ensure_tangents=true
meshes/generate_lods=true
@ -32,6 +34,9 @@ animation/trimming=false
animation/remove_immutable_tracks=true
animation/import_rest_as_RESET=false
import_script/path=""
materials/extract=0
materials/extract_format=0
materials/extract_path=""
_subresources={}
gltf/naming_version=1
gltf/embedded_image_handling=1

View file

@ -21,6 +21,8 @@ dest_files=["res://.godot/imported/Floor_Emitter_0.png-80f8ab069919460163571a408
compress/mode=3
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
@ -28,6 +30,10 @@ mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load diff

View file

@ -3390,7 +3390,7 @@
// entity 192
{
"classname" "marker_spawn_enemy_fairy_small_t1"
"origin" "-168 392 62"
"origin" "-176 372 62"
}
// entity 193
{

View file

@ -1,10 +1,11 @@
[gd_scene load_steps=7 format=3 uid="uid://d4ek8xjuh6y11"]
[gd_scene load_steps=8 format=3 uid="uid://d4ek8xjuh6y11"]
[ext_resource type="Script" uid="uid://dpibtd73awwp7" path="res://Scripts/Actors/ScriptableBulletsEmitter3D.cs" id="1_dtfaj"]
[ext_resource type="Script" uid="uid://ddsqqfx1usc3j" path="res://Scripts/Resources/DamageResistance.cs" id="2_dtfaj"]
[ext_resource type="Resource" uid="uid://bes254wblt1lm" path="res://Resources/Bullets/3D/Explosion_Harmless_Small_3D.tres" id="2_o5sow"]
[ext_resource type="PackedScene" uid="uid://sy821kigcoqx" path="res://3D/BlockbenchModels/FloorEmitter/Floor_Emitter.gltf" id="3_ro7iq"]
[ext_resource type="Script" uid="uid://bf5f2phitdqw8" path="res://Scripts/Actors/BulletSpawner3D.cs" id="4_0cjnq"]
[ext_resource type="Script" uid="uid://c077xadpua5iy" path="res://Scripts/Actors/3D/OpenCloseActorAnimationManager3D.cs" id="6_0cjnq"]
[sub_resource type="CylinderShape3D" id="CylinderShape3D_ro7iq"]
height = 0.297607
@ -20,10 +21,22 @@ ExplosionData = ExtResource("2_o5sow")
DamageResistances = Array[ExtResource("2_dtfaj")]([])
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00549316, 0.116073, -0.000488281)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00549316, -0.08682054, -0.000488281)
shape = SubResource("CylinderShape3D_ro7iq")
[node name="blockbench_export" parent="." instance=ExtResource("3_ro7iq")]
[node name="BulletSpawner3D" type="Node3D" parent="."]
script = ExtResource("4_0cjnq")
[node name="AnimationManager" type="Node" parent="." node_paths=PackedStringArray("AnimationPlayer")]
script = ExtResource("6_0cjnq")
AnimationPlayer = NodePath("../blockbench_export/AnimationPlayer")
OpeningAnimationName = &"TurnOn"
ClosingAnimationName = &"TurnOff"
OpenAnimationName = &"On"
ClosedAnimationName = &"Off"
[connection signal="StateChanged" from="." to="AnimationManager" method="Toggle"]
[editable path="blockbench_export"]

View file

@ -0,0 +1,8 @@
[gd_resource type="StandardMaterial3D" load_steps=2 format=3 uid="uid://con430p41hhsc"]
[ext_resource type="Texture2D" uid="uid://drtxchcin1anl" path="res://textures/Floors/Floor131.png" id="1_dml21"]
[resource]
albedo_texture = ExtResource("1_dml21")
metallic_specular = 0.0
texture_filter = 2

View file

@ -0,0 +1,8 @@
[gd_resource type="StandardMaterial3D" load_steps=2 format=3 uid="uid://c35uhp02xpspx"]
[ext_resource type="Texture2D" uid="uid://csxk8i0aweel" path="res://textures/Floors/Floor295.png" id="1_a67n4"]
[resource]
albedo_texture = ExtResource("1_a67n4")
metallic_specular = 0.0
texture_filter = 2

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,27 @@
[gd_resource type="Resource" script_class="BulletScript3D" load_steps=6 format=3 uid="uid://ddw7u1nudixdv"]
[ext_resource type="Resource" uid="uid://dpnauedcubupa" path="res://Resources/Bullets/3D/rice_bullet_small_red_3D.tres" id="1_k1eey"]
[ext_resource type="Script" uid="uid://b5s5mjuk1rng5" path="res://Scripts/Resources/TimeModifier.cs" id="2_7dhjl"]
[ext_resource type="Script" uid="uid://bxiprx5nwmpnu" path="res://Scripts/AttackPatterns/ShootingPattern3D.cs" id="3_ou3hf"]
[ext_resource type="Script" uid="uid://w8hcpu68ssq" path="res://Scripts/Resources/BulletScripts/BulletScript3D.cs" id="4_748vc"]
[sub_resource type="Resource" id="Resource_k1eey"]
script = ExtResource("3_ou3hf")
LoopType = 1
BulletResource = ExtResource("1_k1eey")
bulletCount = 1
UseParentRotationOffset = true
duration = 0.5
spread = 0.0
burstInterval = 0.0
ShotsPerBurst = 1
BurstRate = 0.5
_targetPlayer = true
OverrideDamage = true
DamageOverride = 20.0
metadata/_custom_type_script = "uid://bxiprx5nwmpnu"
[resource]
script = ExtResource("4_748vc")
Patterns = Array[Object]([SubResource("Resource_k1eey")])
metadata/_custom_type_script = "uid://w8hcpu68ssq"

View file

@ -38,6 +38,11 @@ public partial class OpenCloseActorAnimationManager3D : Node
}
}
public void Toggle(bool state)
{
AnimationPlayer.Play(state ? OpeningAnimationName : ClosingAnimationName);
}
public void PlayOpening()
{
AnimationPlayer.Play(OpeningAnimationName);

View file

@ -0,0 +1,23 @@
using Godot;
namespace Cirno.Scripts.Actors._3D;
public partial class Turret3DAnimator : Node
{
[Export] public AnimationPlayer Animator { get; private set; }
[Export] public StringName OnAnimationName { get; private set; }
[Export] public StringName OffAnimationName { get; private set; }
public void ChangeState(bool state)
{
if (state)
{
Animator?.Play(OnAnimationName);
}
else
{
Animator?.Play(OffAnimationName);
}
}
}

View file

@ -0,0 +1 @@
uid://cbnblvav5ck8a

View file

@ -23,6 +23,8 @@ public partial class ScriptableBulletsEmitter3D : Destructible3D, IActivable, IS
[Export]
public bool EmitOnStart { get; set; } = false;
[Export]
public bool IndestructibleWhileDisabled { get; set; } = true;
// [Export] public bool Indestructible { get; private set; } = false;
// [Export] public float Health = 1f;
//
@ -32,7 +34,8 @@ public partial class ScriptableBulletsEmitter3D : Destructible3D, IActivable, IS
[Signal]
public delegate void StateChangedEventHandler(bool isEmitting);
private bool _isActive = false;
//private BulletScript _scriptInstance;
@ -63,7 +66,8 @@ public partial class ScriptableBulletsEmitter3D : Destructible3D, IActivable, IS
_isActive = true;
ScriptMachine.Start();
}
EmitSignal(SignalName.StateChanged, _isActive);
EmitSignalStateChanged(_isActive);
//EmitSignal(SignalName.StateChanged, _isActive);
}
public override void _func_godot_apply_properties(Dictionary<string, Variant> props)
@ -116,7 +120,8 @@ public partial class ScriptableBulletsEmitter3D : Destructible3D, IActivable, IS
ScriptMachine.Start();
}
EmitSignal(SignalName.StateChanged, _isActive);
EmitSignalStateChanged(_isActive);
//EmitSignal(SignalName.StateChanged, _isActive);
return true;
}

83
addons/laser/laser.gd Normal file
View file

@ -0,0 +1,83 @@
extends Node3D
@onready var laserRay = $Laser
@onready var beamSegment = load("res://addons/laser/laser_beam.tscn")
@onready var laser = load("res://addons/laser/laser.tscn")
const laserLength = 100
const laserDensity = 1.5
const reflectLayer = 2
var points = []
var splits = []
var truePos = null
var trueRot = null
signal openDoor(door)
#since raycast moves all around, this funciton returns it to the starting location
#starting location and rotation should be changed to change the permanent place of the laser
#do not try to change the rotation or position of the parent Node3D to change the starting point
#and trajectory of the laser. Please use truePos and trueRot
func positions():
laserRay.global_position = truePos
laserRay.target_position = trueRot
func _ready():
laserRay.target_position = laserRay.target_position*laserLength
truePos = laserRay.global_position
trueRot = laserRay.target_position*laserLength
var reflectTarget = null
func _process(delta):
points = [laserRay.global_position] #cleans the list of places the laser goes
while true:
laserRay.force_raycast_update()
if laserRay.is_colliding(): #check if laser in current trajectory is colliding with anything
if laserRay.get_collider().collision_layer == reflectLayer: #checks if object is reflective
reflect()
else:
points.append(laserRay.get_collision_point())
updateLaserBeam()
positions()
break
else: #if not colliding, it is assumed that it will go on to infinity and beyond.
if reflectTarget != null:
if points[-1] != laserRay.global_position + (reflectTarget*laserLength):
points.append(laserRay.global_position + (reflectTarget*laserLength))
else:
if points[-1] != laserRay.global_position + (laserRay.target_position*laserLength):
points.append(laserRay.global_position + (laserRay.target_position*laserLength))
updateLaserBeam()
positions()
break
func updateLaserBeam(): #connects the points with spheres
for i in range(0, $Beams.get_child_count()):
$Beams.get_child(i).queue_free()
for i in range(0, len(points)-1):
var line = points[i+1] - points[i]
var direction = (line.normalized())/laserDensity
var pos = points[i]
for j in range(0, (line/direction).x):
var instance = beamSegment.instantiate()
$Beams.add_child(instance)
$Beams.get_child(-1).global_position = pos
pos = pos + direction
func reflect():
reflectTarget = ((laserRay.get_collision_point() - laserRay.global_position)).bounce(laserRay.get_collision_normal())
laserRay.global_position = laserRay.get_collision_point()
laserRay.target_position = reflectTarget*laserLength
points.append(laserRay.global_position)
updateLaserBeam()
#this whole sequence goes like this: laser hits reflective object, move start of
#laser to the hit point, logs the laser's current position, aims the laser the way
#it should based on the bounce function, sees if it hits any reflective surface,
#and repeat

View file

@ -0,0 +1 @@
uid://cuwmjh8siacg1

14
addons/laser/laser.tscn Normal file
View file

@ -0,0 +1,14 @@
[gd_scene load_steps=2 format=3 uid="uid://cdxjy1yy8tqeu"]
[ext_resource type="Script" uid="uid://cuwmjh8siacg1" path="res://addons/laser/laser.gd" id="1_xyxma"]
[node name="Node3D" type="Node3D"]
script = ExtResource("1_xyxma")
[node name="Laser" type="RayCast3D" parent="."]
target_position = Vector3(1, 1, 2.08165e-12)
collision_mask = 7
[node name="Beams" type="Node3D" parent="."]
[node name="Splits" type="Node3D" parent="."]

View file

@ -0,0 +1,14 @@
[gd_scene load_steps=3 format=3 uid="uid://wfbn16mxdrtl"]
[sub_resource type="SphereMesh" id="SphereMesh_nag17"]
radius = 0.1
height = 0.2
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_jodxn"]
albedo_color = Color(1, 0, 0, 1)
emission_enabled = true
emission = Color(1, 0, 0, 1)
[node name="laserBeam" type="MeshInstance3D"]
mesh = SubResource("SphereMesh_nag17")
surface_material_override/0 = SubResource("StandardMaterial3D_jodxn")