made bullet with a camera on the end. other tweaks
This commit is contained in:
71
scripts/bullet_tracking.gd
Normal file
71
scripts/bullet_tracking.gd
Normal file
@@ -0,0 +1,71 @@
|
||||
extends RigidBody3D
|
||||
|
||||
@export var collision_shape : Node
|
||||
|
||||
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
|
||||
var bullet_active = true
|
||||
var bullet_target : Node
|
||||
|
||||
@onready var mesh = $Cylinder
|
||||
@onready var particles = $GPUParticles3D
|
||||
@onready var enemy_particles = $GPUParticlesEnemy
|
||||
@onready var hit_indicator = $Audio/HitIndicator
|
||||
@onready var ray: RayCast3D = $RayCast3D
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
linear_velocity += player_velocity
|
||||
visible = false
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _physics_process(delta):
|
||||
|
||||
linear_velocity = transform.basis * Vector3(0, 0, -bullet_speed)
|
||||
|
||||
if bullet_target != null:
|
||||
look_at(bullet_target.global_position)
|
||||
|
||||
distance_from_player = abs(self.global_position - player_position)
|
||||
|
||||
if distance_from_player.length() > 1.5:
|
||||
visible = true
|
||||
|
||||
func _on_body_entered(body: Node) -> void:
|
||||
|
||||
if !body.is_in_group("player"):
|
||||
|
||||
ray.enabled = false
|
||||
|
||||
if ray.is_colliding():
|
||||
var ray_body = ray.get_collider()
|
||||
if ray_body != null:
|
||||
#bullethole effect
|
||||
ray_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())
|
||||
|
||||
if body.is_in_group("switch"):
|
||||
body.hit()
|
||||
|
||||
|
||||
if body.is_in_group("breakable"):
|
||||
var current_velocity = transform.basis * Vector3(0,0,-1 * bullet_force_mod)
|
||||
body.breaking(current_velocity)
|
||||
despawn()
|
||||
|
||||
func despawn():
|
||||
#visible = false
|
||||
#collision_shape.disabled = true
|
||||
#await get_tree().create_timer(1).timeout
|
||||
queue_free()
|
||||
Reference in New Issue
Block a user