Files
fps_project_1/scripts/bullet.gd

71 lines
1.9 KiB
GDScript

extends RigidBody3D
var bullet_speed
var bullet_drop
var random_spread_amt
var bullet_damage
var instance_bullethole
var bullet_force_mod = 1.0
var distance_from_player
var player_position
var player_velocity
@onready var mesh = $Cylinder
@onready var particles = $GPUParticles3D
@onready var enemy_particles = $GPUParticlesEnemy
@onready var gunbullet1 = $gunbullet1/Cylinder
@onready var hit_indicator = $Audio/HitIndicator
# 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):
distance_from_player = abs(self.global_position - player_position)
if distance_from_player.x > 2 or distance_from_player.y > 2 or distance_from_player.z > 2:
visible = true
func _on_body_entered(body: Node) -> void:
if !body.is_in_group("player"):
mesh.visible = false
#bullethole effect
#body.add_child(instance_bullethole)
#instance_bullethole.global_transform.origin = global_position
#if (abs(body.get_collision_normal().y) > 0.99):
#instance_bullethole.look_at(body.get_collision_point() + body.get_collision_normal(), Vector3(0,0,1))
#else:
#instance_bullethole.look_at(body.get_collision_point() + body.get_collision_normal())
##move rigidbodies
#if body.is_in_group("scene_rigidbody"):
#body.linear_velocity += transform.basis * Vector3(0,0,-1 * bullet_force_mod)
if body.is_in_group("breakable"):
var current_velocity = transform.basis * Vector3(0,0,-1 * bullet_force_mod)
body.breaking(current_velocity)
if body.is_in_group("enemy_target"):
print("enemy target hit")
hit_indicator.play()
enemy_particles.emitting = true
body.hit(bullet_damage)
if body.is_in_group("switch"):
body.hit()
#await get_tree().create_timer(1.0).timeout
queue_free()