blunderbuss working

This commit is contained in:
Derek
2024-11-23 16:27:50 -06:00
parent da6ac13cf7
commit 05b8c0d760
22 changed files with 1003 additions and 108 deletions

67
scripts/shotgun_pellet.gd Normal file
View File

@@ -0,0 +1,67 @@
extends RigidBody3D
@export var max_bounces : int = 10
@onready var collision_shape: CollisionShape3D = $CollisionShape3D
@onready var mesh: MeshInstance3D = $MeshInstance3D
@onready var material = mesh.get_surface_override_material(0)
var bullet_force_mod
var bullet_damage
var player_position
var bounces = 0
var start_time
var end_time
const EMISSION_MAX : float = 20
const EMISSION_LIFETIME : float = 2 #in seconds
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
visible = false
start_time = Time.get_ticks_msec()
end_time = start_time + (EMISSION_LIFETIME * 1000)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
var current_time = (Time.get_ticks_msec())/end_time
material.emission_energy_multiplier = clamp(lerp(EMISSION_MAX,0.0,current_time),0,EMISSION_MAX)
var 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:
bounces += 1
if bounces >= max_bounces:
despawn()
if body != null and !body.is_in_group("player"):
if body.is_in_group("enemy_target"):
SignalBus.emit_signal("enemy_hit")
body.hit(bullet_damage)
if body.is_in_group("switch"):
body.hit()
#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)
func despawn():
collision_shape.disabled = true
await get_tree().create_timer(1).timeout
self.queue_free()
func _on_timer_timeout() -> void:
despawn()