-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectileSpawner.gd
More file actions
142 lines (126 loc) · 4.28 KB
/
Copy pathProjectileSpawner.gd
File metadata and controls
142 lines (126 loc) · 4.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
extends Marker3D
# Apologees for messy scripts, this was my first complete game
@export var active := true:
set(val):
if(val == true && shotspeed == 0):
Spawnproj()
active = val
@export var base : CharacterBody3D
@export var target : Node3D
@export_enum("FireTowardsTarget","Predictive","Spray","PredictiveSpray","Shower","Ring","Sphere","VorpSpray") var behavior : String
@export var shotspeed : float = 1
@export_enum("Regular","Homing","Homingacc", "Growing","Homing&Growing","Accellerating","Slowing") var type : String
#@export_enum("Regular","Homing","Homingacc", "Growing","Homing&Growing","Accellerating","Slowing") var type2 : String
@export var size := 1.
@export var activetime := 5.
@export var damage := 1
@export var projspeed : float = 1
# Messy code, property used for "type" settings
@export var bonusproportey := 1.
@onready var proj = preload("res://Projectiles/Projectile.tscn")
@export var plusdeg := Vector3.ZERO
@export var parent : Node3D
var pos : Vector3:
set(val):
$MeshInstance3D.global_position = val
pos = val
var rand = RandomNumberGenerator.new()
var time : float = 0
func _process(delta):
if(!active):
return
# Simple timer spawns shotspeed amount per second
time += delta
if(time > 1/shotspeed):
SpawnProjectile()
time -= 1/shotspeed
func SpawnProjectile():
if(!Globals.projactive or time == 0):
return
if(base && !base.alive):
return
var spread = 20
if(!target):
target = base.target
var height = Vector3(1.2,0,0)
match behavior:
"FireTowardsTarget":
if(target):
pos = target.global_position
$Lookat.look_at(pos)
global_rotation_degrees = $Lookat.global_rotation_degrees + height
"Predictive":
pos = target.global_position + (target.velocity.normalized() * global_position.distance_to(target.global_position)/projspeed * .8 + height)
$Lookat.look_at(pos)
#$Lookat.global_rotation_degrees.x = clamp($Lookat.global_rotation_degrees.x,-1,INF)
global_rotation_degrees = $Lookat.global_rotation_degrees
"Spray":
pos = target.global_position
$Lookat.look_at(pos)
global_rotation_degrees = $Lookat.global_rotation_degrees + Vector3(1.2,0,0) + Vector3(0,rand.randf_range(-spread,spread),0)
"PredictiveSpray":
pos = target.global_position + (target.velocity.normalized() * global_position.distance_to(target.global_position)/projspeed * .8 + height)
$Lookat.look_at(pos)
#$Lookat.global_rotation_degrees.x = clamp($Lookat.global_rotation_degrees.x,-1,INF)
global_rotation_degrees = $Lookat.global_rotation_degrees + Vector3(0,rand.randf_range(-spread,spread),0)
"Ring":
$Lookat.look_at(target.global_position)
await Spawnproj("Ring")
return
"Sphere":
var previusplusdeg : Vector3 = plusdeg
for i in range(0,360,5):
plusdeg.z = i
await Spawnproj("Ring")
plusdeg = previusplusdeg
#for i in range(0,360,36):
#for j in range(0,360,10):
#$Lookat.rotation_degrees = Vector3(j,i,0)
#global_rotation_degrees = $Lookat.global_rotation_degrees
#await Spawnproj()
"VorpSpray":
for i in range(0,360,10):
for j in range(0,360,10):
$Lookat.rotation_degrees = Vector3(j,i,0)
global_rotation_degrees = $Lookat.global_rotation_degrees
await Spawnproj()
await get_tree().create_timer(bonusproportey).timeout
global_rotation_degrees += plusdeg
Spawnproj()
@export var target2 : Node
func Spawnproj(projtype = "Sphere"):
var _proj
# Object Pooling function, Make sure you have global script with this function
if(projtype == "Sphere"):
_proj = Globals.Projectile()
var curproj
if(_proj):
curproj = _proj
else:
match projtype:
"Sphere":
curproj = proj.instantiate()
"Ring":
curproj = Globals.Projectile("Ring")
#print('ring')
curproj.plusdeg = plusdeg
curproj.global_position = global_position
curproj.speed = 30 * projspeed
curproj.vel = (global_position - $Marker3D.global_position).normalized()
curproj.target = target
curproj.type = str(type)
curproj.bonusproportey = bonusproportey
curproj.size = size
curproj.timemax = activetime
curproj.damage = damage
if(base):
curproj.exception = base.name
if(_proj && projtype != "Ring"):
curproj.set_process(true)
curproj.show()
curproj.process_mode = Node.PROCESS_MODE_INHERIT
else:
if(parent):
parent.add_child(curproj)
return
get_tree().add_child(curproj)