refactored bullet script, broke shotgun pellets which will need to be fixed
This commit is contained in:
@@ -4,75 +4,13 @@ extends Projectile
|
||||
@onready var mesh = $Cylinder
|
||||
@onready var particles = $GPUParticles3D
|
||||
@onready var enemy_particles = $GPUParticlesEnemy
|
||||
@onready var hit_indicator = $Audio/HitIndicator
|
||||
@onready var ray: RayCast3D = $RayCast3D
|
||||
@onready var water_leak : Resource = preload("res://assets/water_leak.tscn")
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
|
||||
visible = false
|
||||
linear_velocity += transform.basis * Vector3(0, 0, -bullet_speed) + player_velocity
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _physics_process(delta):
|
||||
|
||||
angular_velocity = Vector3(0,0,0)
|
||||
|
||||
var distance_from_player = abs(self.global_position - player_position)
|
||||
|
||||
if distance_from_player.length() > 2:
|
||||
visible = true
|
||||
|
||||
if ray.is_colliding():
|
||||
var body = ray.get_collider()
|
||||
if body != null and !body.is_in_group("player"):
|
||||
|
||||
mesh.visible = false
|
||||
ray.enabled = false
|
||||
|
||||
if body.has_method("hit"):
|
||||
hit_indicator.play()
|
||||
enemy_particles.emitting = true
|
||||
body.hit(bullet_damage)
|
||||
|
||||
#bullethole effect
|
||||
body.add_child(instance_bullethole)
|
||||
instance_bullethole.global_transform.origin = ray.get_collision_point()
|
||||
if (abs(ray.get_collision_normal().y) > 0.99):
|
||||
instance_bullethole.look_at(ray.get_collision_point() + ray.get_collision_normal(), Vector3(0,0,1))
|
||||
else:
|
||||
instance_bullethole.look_at(ray.get_collision_point() + ray.get_collision_normal())
|
||||
instance_bullethole.rotation.z = deg_to_rad(randf_range(0,360))
|
||||
|
||||
#range target
|
||||
if body.is_in_group("range_target"):
|
||||
body.add_marker(ray.get_collision_point(),ray.global_rotation)
|
||||
|
||||
# Leaking effect
|
||||
if body.is_in_group("leak"):
|
||||
var leakspawn = water_leak.instantiate()
|
||||
body.add_child(leakspawn)
|
||||
leakspawn.global_transform.origin = ray.get_collision_point()
|
||||
if (abs(ray.get_collision_normal().y) > 0.99):
|
||||
leakspawn.look_at(ray.get_collision_point() + ray.get_collision_normal(), Vector3(0,0,1))
|
||||
else:
|
||||
leakspawn.look_at(ray.get_collision_point() + ray.get_collision_normal())
|
||||
leakspawn.rotation.z = deg_to_rad(randf_range(0,360))
|
||||
|
||||
if body.is_in_group("switch"):
|
||||
body.hit(bullet_damage)
|
||||
|
||||
if body.is_in_group("breakable"):
|
||||
var current_velocity = transform.basis * Vector3(0,0,-1 * bullet_force_mod)
|
||||
ray.get_collider().breaking(current_velocity)
|
||||
|
||||
queue_free()
|
||||
|
||||
func _on_body_entered(body: Node) -> void:
|
||||
if !body.is_in_group("player"):
|
||||
await get_tree().create_timer(.1).timeout
|
||||
mesh.visible = false
|
||||
|
||||
func despawn():
|
||||
queue_free()
|
||||
|
||||
Reference in New Issue
Block a user