turret tweaks
This commit is contained in:
@@ -3,6 +3,7 @@ extends Node3D
|
||||
|
||||
@export var player : Node
|
||||
@export var money = 250
|
||||
@export var health = 3
|
||||
@export var gun_1 : Resource
|
||||
@export var gun_2 : Resource
|
||||
var held_guns = []
|
||||
@@ -30,7 +31,7 @@ func _ready():
|
||||
gun_spawn(0)
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
func _process(_delta):
|
||||
pass
|
||||
|
||||
func gun_spawn(index):
|
||||
|
||||
@@ -67,7 +67,6 @@ func _process(delta):
|
||||
|
||||
|
||||
if ray.get_collider().is_in_group("enemy"):
|
||||
print("enemy hit")
|
||||
hit_indicator.play()
|
||||
enemy_particles.emitting = true
|
||||
ray.get_collider().hit(bullet_damage)
|
||||
|
||||
@@ -4,7 +4,6 @@ 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
|
||||
@@ -16,7 +15,7 @@ var player
|
||||
@onready var timer = $Timer
|
||||
@onready var gunbullet1 = $gunbullet1/Cylinder
|
||||
@onready var hit_indicator = $Audio/HitIndicator
|
||||
|
||||
@export var bullethole : Resource
|
||||
|
||||
|
||||
var rng = RandomNumberGenerator.new()
|
||||
@@ -40,4 +39,21 @@ func _process(delta):
|
||||
position += transform.basis * Vector3(0, 0, -bullet_speed) * delta
|
||||
rotation.x = clamp(rotation.x - delta * bullet_drop,deg_to_rad(-90),deg_to_rad(90))
|
||||
|
||||
|
||||
if ray.is_colliding() and !ray.get_collider().is_in_group("player"):
|
||||
|
||||
mesh.visible = false
|
||||
ray.enabled = false
|
||||
|
||||
#bullethole effect
|
||||
var instance_bullethole = bullethole.instantiate()
|
||||
ray.get_collider().add_child(instance_bullethole)
|
||||
instance_bullethole.global_transform.origin = ray.get_collision_point()
|
||||
instance_bullethole.look_at(ray.get_collision_point() + ray.get_collision_normal(), Vector3.UP)
|
||||
|
||||
#move rigidbodies
|
||||
if ray.get_collider().is_in_group("scene_rigidbody"):
|
||||
ray.get_collider().linear_velocity += transform.basis * Vector3(0,0,-1 * bullet_force_mod)
|
||||
|
||||
if ray.get_collider().is_in_group("breakable"):
|
||||
var current_velocity = transform.basis * Vector3(0,0,-1 * bullet_force_mod)
|
||||
ray.get_collider().breaking(current_velocity)
|
||||
|
||||
@@ -67,7 +67,7 @@ func _ready():
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
func _process(_delta):
|
||||
pass
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ func reload_finished():
|
||||
level_control.ammo_reserve[gun_index] -= level_control.ammo_reserve[gun_index]
|
||||
#player.reloading = false
|
||||
|
||||
func shoot(player,delta):
|
||||
func shoot(delta):
|
||||
|
||||
if level_control.ammo_current[gun_index] > 0 and cycle_count > 0:
|
||||
if !anim_player.is_playing():
|
||||
@@ -121,7 +121,7 @@ func shoot(player,delta):
|
||||
anim_player.play("empty")
|
||||
audio_empty.play()
|
||||
|
||||
func reload(player,delta):
|
||||
func reload(delta):
|
||||
if level_control.ammo_current[gun_index] < max_ammo and player.gun.anim_player.get_current_animation() != "reload" and level_control.ammo_reserve[gun_index] > 0:
|
||||
#player.reloading = true
|
||||
anim_player.play("reload")
|
||||
|
||||
@@ -158,14 +158,14 @@ func _physics_process(delta):
|
||||
|
||||
# Reloading
|
||||
if Input.is_action_just_pressed("reload"):
|
||||
gun.reload(self,delta)
|
||||
gun.reload(delta)
|
||||
|
||||
if Input.is_action_pressed("inspect") and !gun.anim_player.is_playing():
|
||||
gun.anim_player.play("inspect")
|
||||
|
||||
# Shooting & fire modes
|
||||
if Input.is_action_pressed("shoot"):
|
||||
gun.shoot(self,delta)
|
||||
gun.shoot(delta)
|
||||
|
||||
if Input.is_action_just_released("shoot"):
|
||||
gun.cycle_count = gun.cycle_count_start
|
||||
|
||||
@@ -124,7 +124,7 @@ func reload_finished():
|
||||
await get_tree().create_timer(.01).timeout
|
||||
player.reloading = false
|
||||
|
||||
func shoot(player,delta):
|
||||
func shoot(delta):
|
||||
if level_control.ammo_current[gun_index] > 0 and cycle_count > 0:
|
||||
if !anim_player.is_playing():
|
||||
level_control.ammo_current[gun_index] -= 1
|
||||
@@ -159,7 +159,7 @@ func fire(delta):
|
||||
chamber.rotate_object_local(Vector3(0,-1,0),deg_to_rad(60))
|
||||
|
||||
|
||||
func reload(player,delta):
|
||||
func reload(delta):
|
||||
if level_control.ammo_current[gun_index] < max_ammo and player.gun.anim_player.get_current_animation() != "reload" and level_control.ammo_reserve[gun_index] > 0:
|
||||
anim_player.play("reload")
|
||||
audio_reload.play()
|
||||
|
||||
@@ -4,28 +4,31 @@ var player = null
|
||||
@export var health = 3
|
||||
@export var number_of_drops = 3
|
||||
|
||||
const SPEED = 0.0
|
||||
@export var SPEED = 3.0
|
||||
const MAX_LV = 10
|
||||
const MAX_AV = 10
|
||||
|
||||
@export var player_path : NodePath
|
||||
@export var bullet : Resource
|
||||
@export var casing : Resource
|
||||
@export var bullet_speed = 150
|
||||
@export var bullet_drop = .1
|
||||
@export var random_spread_amt = .01
|
||||
@export var bullet_damage = 1
|
||||
@export var turret_look_speed = 3
|
||||
@export var turret_look_speed = 5
|
||||
|
||||
@onready var nav_agent = $NavigationAgent3D
|
||||
@onready var target = $body/target
|
||||
@onready var movement_shape = $MovementShape
|
||||
@onready var barrel_1 = $TurretLook/Turret/Barrel1
|
||||
@onready var barrel_2 = $TurretLook/Turret/Barrel2
|
||||
@onready var casing_ejector = $TurretLook/Turret/CasingEjector
|
||||
@onready var prefire_timer = $Timers/prefire_timer
|
||||
@onready var postfire_timer = $Timers/postfire_timer
|
||||
@onready var retarget_timer = $Timers/retarget_timer
|
||||
@onready var turret_look_next = $TurretLookNext
|
||||
@onready var spider_look_next = $SpiderLookNext
|
||||
@onready var body = $body
|
||||
|
||||
|
||||
@onready var turret = $TurretLook/Turret
|
||||
@@ -45,9 +48,12 @@ var body_look_to
|
||||
|
||||
func _ready():
|
||||
player = get_node(player_path)
|
||||
postfire_timer.start()
|
||||
turret_material.emission_enabled = false
|
||||
retarget_timer.start()
|
||||
|
||||
#randomly start the postfire timer so enemy turrets aren't synced
|
||||
var random_time = rng.randf_range(0,5)
|
||||
await get_tree().create_timer(random_time).timeout
|
||||
postfire_timer.start()
|
||||
|
||||
func _process(delta):
|
||||
velocity = Vector3.ZERO
|
||||
@@ -57,7 +63,10 @@ func _process(delta):
|
||||
var next_nav_point = nav_agent.get_next_path_position()
|
||||
velocity = (next_nav_point - global_transform.origin).normalized() * SPEED
|
||||
|
||||
turret_look_next.look_at(Vector3(player.global_position.x, global_position.y, player.global_position.z), Vector3.UP)
|
||||
#FIX BODY ROTATION
|
||||
#spider_look_next.look_at(Vector3(player.global_position.x, global_position.y, player.global_position.z), Vector3.UP)
|
||||
#self.rotation = lerp(self.rotation, spider_look_next.rotation, delta * 1)
|
||||
|
||||
turret_look_next.look_at(player.global_position,Vector3.UP)
|
||||
turret_look.rotation = lerp(turret_look.rotation,turret_look_next.rotation,delta * turret_look_speed)
|
||||
|
||||
@@ -118,22 +127,28 @@ func _on_prefire_timer_timeout():
|
||||
#barrel 2 fire
|
||||
var instance_bullet2 = bullet.instantiate()
|
||||
instance_bullet2.position = barrel_2.global_position
|
||||
instance_bullet2.transform.basis = barrel_2.global_transform.basis
|
||||
instance_bullet2.transform.basis = barrel_2.global_transform.basis
|
||||
instance_bullet2.bullet_speed = bullet_speed
|
||||
instance_bullet2.bullet_drop = bullet_drop
|
||||
instance_bullet2.random_spread_amt = random_spread_amt
|
||||
instance_bullet2.bullet_damage = bullet_damage
|
||||
get_tree().get_root().add_child(instance_bullet2)
|
||||
turret_material.emission_enabled = false
|
||||
|
||||
var instance_casing = casing.instantiate()
|
||||
instance_casing.position = casing_ejector.global_position
|
||||
instance_casing.transform.basis = casing_ejector.global_transform.basis
|
||||
var instance_casing2 = casing.instantiate()
|
||||
instance_casing2.position = casing_ejector.global_position
|
||||
instance_casing2.transform.basis = casing_ejector.global_transform.basis
|
||||
get_tree().get_root().add_child(instance_casing)
|
||||
get_tree().get_root().add_child(instance_casing2)
|
||||
|
||||
prefire_timer.stop()
|
||||
postfire_timer.start()
|
||||
|
||||
|
||||
func _on_postfire_timer_timeout():
|
||||
#if turret_look.is_colliding() and turret_look.get_collider().is_in_group("player"):
|
||||
#if turret_look_next.is_colliding() and turret_look_next.get_collider().is_in_group("player"):
|
||||
prefire_timer.start()
|
||||
turret_material.emission_enabled = true
|
||||
|
||||
|
||||
func _on_retarget_timer_timeout():
|
||||
pass #turret_look_next.look_at(player.global_position,Vector3.UP)
|
||||
|
||||
Reference in New Issue
Block a user