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)
|
||||
|
||||
Reference in New Issue
Block a user