refactored bullet script, broke shotgun pellets which will need to be fixed
This commit is contained in:
@@ -3,6 +3,8 @@ class_name Projectile
|
||||
|
||||
@export var collision_raycast_3d : RayCast3D
|
||||
|
||||
const BULLET_HOLE = preload("res://assets/bullet_hole.tscn")
|
||||
|
||||
var player_position
|
||||
var player_velocity
|
||||
var bullet_active = true
|
||||
@@ -16,13 +18,61 @@ var blast_radius
|
||||
func _ready() -> void:
|
||||
visible = false
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
var distance_from_player = abs(self.global_position - player_position)
|
||||
func _physics_process(delta: float) -> void:
|
||||
#make bullet visible when far enough from player
|
||||
if !visible:
|
||||
var distance_from_player = abs(self.global_position - player_position)
|
||||
|
||||
if distance_from_player.length() > 2.0:
|
||||
visible = true
|
||||
|
||||
if distance_from_player.length() > 2:
|
||||
visible = true
|
||||
if collision_raycast_3d != null:
|
||||
if collision_raycast_3d.is_colliding():
|
||||
var body = collision_raycast_3d.get_collider()
|
||||
damage(body)
|
||||
|
||||
collision_ray_length_adj()
|
||||
|
||||
func collision_ray():
|
||||
func damage(body):
|
||||
if body != null and !body.is_in_group("player"):
|
||||
|
||||
if collision_raycast_3d != null:
|
||||
collision_raycast_3d.enabled = false
|
||||
|
||||
if body.has_method("hit"):
|
||||
SignalBus.emit_signal("enemy_hit")
|
||||
body.hit(bullet_damage)
|
||||
|
||||
#bullethole effect, eventually add group test for different bullet hole textures
|
||||
add_normal_decal(body,BULLET_HOLE)
|
||||
|
||||
#mark range target
|
||||
if body.is_in_group("range_target") and collision_raycast_3d != null:
|
||||
body.add_marker(collision_raycast_3d.get_collision_point(),collision_raycast_3d.global_rotation)
|
||||
|
||||
#start leaking effect
|
||||
if body.is_in_group("leak") and body.water_leak != null:
|
||||
add_normal_decal(body,body.water_leak)
|
||||
|
||||
#break breakables
|
||||
if body.is_in_group("breakable"):
|
||||
var current_velocity = transform.basis * Vector3(0,0,-1 * bullet_force_mod)
|
||||
collision_raycast_3d.get_collider().breaking(current_velocity)
|
||||
|
||||
queue_free()
|
||||
|
||||
func add_normal_decal(body,instance):
|
||||
if collision_raycast_3d != null:
|
||||
var decal_spawn = instance.instantiate()
|
||||
body.add_child(decal_spawn)
|
||||
decal_spawn.global_transform.origin = collision_raycast_3d.get_collision_point()
|
||||
if (abs(collision_raycast_3d.get_collision_normal().y) > 0.99):
|
||||
decal_spawn.look_at(collision_raycast_3d.get_collision_point() + collision_raycast_3d.get_collision_normal(), Vector3(0,0,1))
|
||||
else:
|
||||
decal_spawn.look_at(collision_raycast_3d.get_collision_point() + collision_raycast_3d.get_collision_normal())
|
||||
decal_spawn.rotation.z = deg_to_rad(randf_range(0,360))
|
||||
|
||||
func collision_ray_length_adj():
|
||||
if collision_raycast_3d != null:
|
||||
#do looking towards velocity
|
||||
#do lenghth of distance traveled next frame
|
||||
|
||||
Reference in New Issue
Block a user