-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectile.gd
More file actions
92 lines (82 loc) · 2.5 KB
/
Copy pathProjectile.gd
File metadata and controls
92 lines (82 loc) · 2.5 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
extends MeshInstance3D
#var SHAPE := preload("res://enemies/ProjectileShape.tres")
@onready var SHAPE : SphereShape3D = $CollisionShape3D.shape
var query := PhysicsShapeQueryParameters3D.new()
@onready var spacestate := get_world_3d().direct_space_state
var damage := 1.
var speed := 30.
@export var vel : Vector3
var rot : Vector3
@export var projtype : String
@export var animationplayer : AnimationPlayer
var target : CharacterBody3D
var exception : String
var timemax := 5.
var type := "Regular"
var bonusproportey
var size := 1.
#@export_enum("Regular","Homing","Splitting","Growing","Large","Stationary") var type : String
func _ready():
set("instance_shader_parameters/offset_fres",.3)
query.shape = SHAPE
query.collide_with_bodies = true
# in decimal binary 2^(layer -1)
query.collision_mask = 256
UI.projectilenumber += 1
scale = Vector3(size,size,size)
var time := 0.
var tm := 0.
func _process(delta):
if(time == 0):
scale = Vector3(size,size,size)
time += delta
tm += delta
if(time > timemax):
Perish()
match type:
"Regular":
global_position += vel * delta * speed
"Homing":
if(!target):
return
global_position += (target.col.global_position - global_position).normalized() * delta * speed
"Growing":
global_position += vel * delta * speed
scale += Vector3(1,1,1) * delta * bonusproportey
"Homingacc":
if(!target):
return
vel += (target.global_position - global_position).normalized() * delta * bonusproportey
vel = vel.normalized()
global_position += vel * delta * speed
"Homing&Growing":
if(!target):
return
global_position += (target.global_position - global_position).normalized() * delta * speed
scale += Vector3(1,1,1) * delta * bonusproportey
"Slowing":
global_position += vel * delta * speed
speed -= delta * bonusproportey * speed
if(speed < 0):
speed = 0
var tim = .02
if(tm > tim):
tm -= tim
CheckCollision()
func CheckCollision():
query.transform = global_transform
var result := spacestate.intersect_shape(query) # could also be collide_shape(), intersect_shape(), cast_motion(), get_rest_info()
if(result):
#queue_free()
var collider = result[0].collider
if(collider.name == exception or collider.name == "Floor"):
return
if(collider.has_method("OnDamageTaken")):
collider.OnDamageTaken(self, 0, 0, damage)
Perish()
func Perish():
var tween = get_tree().create_tween()
set_process(false)
await tween.tween_property(self,"transparency",1,.2).finished
process_mode = Node.PROCESS_MODE_DISABLED
hide()