WIP trying to fix the bullet transform issue

This commit is contained in:
Derek
2024-07-14 18:20:50 -05:00
parent 13dd6f9a81
commit db3b4fdbdc
3 changed files with 35 additions and 32 deletions

File diff suppressed because one or more lines are too long

View File

@@ -31,6 +31,7 @@ var random_spread_start
@export var audio_reload : Node
@onready var player = $"../../../../"
var rng = RandomNumberGenerator.new()
# Called when the node enters the scene tree for the first time.
func _ready():
@@ -56,43 +57,46 @@ func _on_gun_anims_animation_finished(anim_name):
player.ammo_reserve -= player.ammo_reserve
player.reloading = false
func shoot():
if ammo > 0:
if !gun.anim_player.is_playing():
ammo -= 1
#RECOIL fix later to happen over a period of time
camera.rotation.x = clamp(lerp(camera.rotation.x, camera.rotation.x + gun.recoil_amount, delta * 10), deg_to_rad(-90), deg_to_rad(60))
func shoot(player,bullet_ray,delta):
if player.ammo > 0:
if !anim_player.is_playing():
player.ammo -= 1
#RECOIL --- fix later to happen over a period of time
player.camera.rotation.x = clamp(lerp(player.camera.rotation.x, player.camera.rotation.x + recoil_amount, delta * 10), deg_to_rad(-90), deg_to_rad(60))
#(ADD PLAYER KICK HERE. RELATIVE TO GUN POSITION)
gun.audio_fire.pitch_scale = 1 + rng.randf_range(-.2,.2)
gun.audio_fire.play()
gun.anim_player.play("shoot")
audio_fire.pitch_scale = 1 + rng.randf_range(-.2,.2)
audio_fire.play()
anim_player.play("shoot")
# shoot real bullet from camera
if gun_folded == false:
instance_bullet = gun.bullet.instantiate()
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 = gun.bullet_speed
instance_bullet.bullet_drop = gun.bullet_drop
instance_bullet.random_spread_amt = gun.random_spread_amt
instance_bullet.gun = gun
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)
else:
instance_bullet = gun.bullet.instantiate()
instance_bullet.position = gun.barrel_raycast.global_position
instance_bullet.transform.basis = gun.barrel_raycast.global_transform.basis
instance_bullet.bullet_speed = gun.bullet_speed
instance_bullet.bullet_drop = gun.bullet_drop
instance_bullet.random_spread_amt = gun.random_spread_amt
instance_bullet.gun = gun
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)
# Casing transform
instance_casing = gun.casing.instantiate()
instance_casing.position = gun.casing_ejector.global_position
instance_casing.transform.basis = gun.casing_ejector.global_transform.basis
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)
elif !gun.anim_player.is_playing():
gun.anim_player.play("empty")
gun.audio_empty.play()
elif !anim_player.is_playing():
anim_player.play("empty")
audio_empty.play()

View File

@@ -171,7 +171,7 @@ func _physics_process(delta):
# Shooting
if Input.is_action_pressed("shoot"):
gun.shoot()
gun.shoot(self,bullet_ray,delta)
@@ -195,7 +195,6 @@ func _headbob(time) -> Vector3:
var pos = Vector3.ZERO
pos.y = sin(time * BOB_FREQ) * BOB_AMP
pos.x = cos(time * BOB_FREQ / 2) * BOB_AMP
print("hello")
return pos