moved key gun functions into gun script. small glitch in reload animation that I havent diagnosed yet
This commit is contained in:
@@ -57,7 +57,7 @@ func _on_gun_anims_animation_finished(anim_name):
|
||||
player.ammo_reserve -= player.ammo_reserve
|
||||
player.reloading = false
|
||||
|
||||
func shoot(player,bullet_ray,delta):
|
||||
func shoot(player,delta):
|
||||
if player.ammo > 0:
|
||||
if !anim_player.is_playing():
|
||||
player.ammo -= 1
|
||||
@@ -69,34 +69,43 @@ func shoot(player,bullet_ray,delta):
|
||||
anim_player.play("shoot")
|
||||
|
||||
# shoot real bullet from camera
|
||||
|
||||
var instance_bullet = bullet.instantiate()
|
||||
instance_bullet.position = player.bullet_ray.global_position
|
||||
#shoot bullet from real gun if gun is folded up
|
||||
if player.gun_folded == false:
|
||||
var instance_bullet = bullet.instantiate()
|
||||
instance_bullet.position = bullet_ray.global_position
|
||||
instance_bullet.transform.basis = bullet_ray.global_transform.basis
|
||||
instance_bullet.bullet_speed = bullet_speed
|
||||
instance_bullet.bullet_drop = bullet_drop
|
||||
instance_bullet.random_spread_amt = random_spread_amt
|
||||
instance_bullet.gun = self
|
||||
print("bullet coords: " + str(instance_bullet.position))
|
||||
print("bullet transform: " + str(instance_bullet.transform.basis))
|
||||
get_parent().add_child(instance_bullet)
|
||||
instance_bullet.transform.basis = player.bullet_ray.global_transform.basis
|
||||
else:
|
||||
var instance_bullet = bullet.instantiate()
|
||||
instance_bullet.position = barrel_raycast.global_position
|
||||
instance_bullet.transform.basis = barrel_raycast.global_transform.basis
|
||||
instance_bullet.bullet_speed = bullet_speed
|
||||
instance_bullet.bullet_drop = bullet_drop
|
||||
instance_bullet.random_spread_amt = random_spread_amt
|
||||
instance_bullet.gun = self
|
||||
get_parent().add_child(instance_bullet)
|
||||
instance_bullet.transform.basis = barrel_raycast.global_transform.basis
|
||||
instance_bullet.bullet_speed = bullet_speed
|
||||
instance_bullet.bullet_drop = bullet_drop
|
||||
instance_bullet.random_spread_amt = random_spread_amt
|
||||
instance_bullet.gun = self
|
||||
get_tree().get_root().add_child(instance_bullet)
|
||||
|
||||
# Casing transform
|
||||
var instance_casing = casing.instantiate()
|
||||
instance_casing.position = casing_ejector.global_position
|
||||
instance_casing.transform.basis = casing_ejector.global_transform.basis
|
||||
|
||||
get_parent().add_child(instance_casing)
|
||||
get_tree().get_root().add_child(instance_casing)
|
||||
|
||||
elif !anim_player.is_playing():
|
||||
anim_player.play("empty")
|
||||
audio_empty.play()
|
||||
|
||||
|
||||
func reload(player,delta):
|
||||
if player.ammo < max_ammo and player.reloading == false and player.ammo_reserve > 0:
|
||||
player.reloading = true
|
||||
anim_player.play("reload")
|
||||
audio_reload.play()
|
||||
if anim_player.is_playing() and anim_player.current_animation == "reload":
|
||||
if player.ammo == 0:
|
||||
player.ammo = 0
|
||||
else:
|
||||
player.ammo = 1
|
||||
|
||||
func spawn_mag():
|
||||
var instance_mag = mag.instantiate()
|
||||
instance_mag.position = mag_ejector.global_position
|
||||
instance_mag.transform.basis = mag_ejector.global_transform.basis
|
||||
get_tree().get_root().add_child(instance_mag)
|
||||
|
||||
@@ -152,26 +152,14 @@ func _physics_process(delta):
|
||||
|
||||
# Reloading
|
||||
if Input.is_action_just_pressed("reload"):
|
||||
if ammo < gun.max_ammo and reloading == false and ammo_reserve > 0:
|
||||
reloading = true
|
||||
gun.anim_player.play("reload")
|
||||
gun.audio_reload.play()
|
||||
instance_mag = gun.mag.instantiate()
|
||||
await get_tree().create_timer(.28).timeout
|
||||
instance_mag.position = gun.mag_ejector.global_position
|
||||
instance_mag.transform.basis = gun.mag_ejector.global_transform.basis
|
||||
get_parent().add_child(instance_mag)
|
||||
if gun.anim_player.is_playing() and gun.anim_player.current_animation == "reload":
|
||||
if ammo == 0:
|
||||
ammo = 0
|
||||
else:
|
||||
ammo = 1
|
||||
gun.reload(self,delta)
|
||||
|
||||
if Input.is_action_pressed("inspect") and !gun.anim_player.is_playing():
|
||||
gun.anim_player.play("inspect")
|
||||
|
||||
# Shooting
|
||||
if Input.is_action_pressed("shoot"):
|
||||
gun.shoot(self,bullet_ray,delta)
|
||||
gun.shoot(self,delta)
|
||||
|
||||
|
||||
|
||||
@@ -239,8 +227,8 @@ func weapon_tilt(input_x, delta):
|
||||
|
||||
func weapon_sway(delta):
|
||||
mouse_input = lerp(mouse_input, Vector2.ZERO, 10 * delta)
|
||||
weapon_holder.rotation.x = lerp(weapon_holder.rotation.x, mouse_input.y * weapon_rotation_amount, 10 * delta)
|
||||
weapon_holder.rotation.y = lerp(weapon_holder.rotation.y, mouse_input.x * weapon_rotation_amount, 10 * delta)
|
||||
weapon_holder.rotation.x = lerp(weapon_holder.rotation.x, mouse_input.y * weapon_rotation_amount, 1 * delta)
|
||||
weapon_holder.rotation.y = lerp(weapon_holder.rotation.y, mouse_input.x * weapon_rotation_amount, 1 * delta)
|
||||
|
||||
#crosshair.position.x = lerp(crosshair.position.x, mouse_input.x * 100, 2 * delta)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user