WIP trying to fix the bullet transform issue
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -31,6 +31,7 @@ var random_spread_start
|
|||||||
@export var audio_reload : Node
|
@export var audio_reload : Node
|
||||||
|
|
||||||
@onready var player = $"../../../../"
|
@onready var player = $"../../../../"
|
||||||
|
var rng = RandomNumberGenerator.new()
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready():
|
func _ready():
|
||||||
@@ -56,43 +57,46 @@ func _on_gun_anims_animation_finished(anim_name):
|
|||||||
player.ammo_reserve -= player.ammo_reserve
|
player.ammo_reserve -= player.ammo_reserve
|
||||||
player.reloading = false
|
player.reloading = false
|
||||||
|
|
||||||
func shoot():
|
func shoot(player,bullet_ray,delta):
|
||||||
if ammo > 0:
|
if player.ammo > 0:
|
||||||
if !gun.anim_player.is_playing():
|
if !anim_player.is_playing():
|
||||||
ammo -= 1
|
player.ammo -= 1
|
||||||
#RECOIL fix later to happen over a period of time
|
#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))
|
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)
|
#(ADD PLAYER KICK HERE. RELATIVE TO GUN POSITION)
|
||||||
gun.audio_fire.pitch_scale = 1 + rng.randf_range(-.2,.2)
|
audio_fire.pitch_scale = 1 + rng.randf_range(-.2,.2)
|
||||||
gun.audio_fire.play()
|
audio_fire.play()
|
||||||
gun.anim_player.play("shoot")
|
anim_player.play("shoot")
|
||||||
|
|
||||||
# shoot real bullet from camera
|
# shoot real bullet from camera
|
||||||
if gun_folded == false:
|
if player.gun_folded == false:
|
||||||
instance_bullet = gun.bullet.instantiate()
|
var instance_bullet = bullet.instantiate()
|
||||||
instance_bullet.position = bullet_ray.global_position
|
instance_bullet.position = bullet_ray.global_position
|
||||||
instance_bullet.transform.basis = bullet_ray.global_transform.basis
|
instance_bullet.transform.basis = bullet_ray.global_transform.basis
|
||||||
instance_bullet.bullet_speed = gun.bullet_speed
|
instance_bullet.bullet_speed = bullet_speed
|
||||||
instance_bullet.bullet_drop = gun.bullet_drop
|
instance_bullet.bullet_drop = bullet_drop
|
||||||
instance_bullet.random_spread_amt = gun.random_spread_amt
|
instance_bullet.random_spread_amt = random_spread_amt
|
||||||
instance_bullet.gun = gun
|
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)
|
get_parent().add_child(instance_bullet)
|
||||||
else:
|
else:
|
||||||
instance_bullet = gun.bullet.instantiate()
|
var instance_bullet = bullet.instantiate()
|
||||||
instance_bullet.position = gun.barrel_raycast.global_position
|
instance_bullet.position = barrel_raycast.global_position
|
||||||
instance_bullet.transform.basis = gun.barrel_raycast.global_transform.basis
|
instance_bullet.transform.basis = barrel_raycast.global_transform.basis
|
||||||
instance_bullet.bullet_speed = gun.bullet_speed
|
instance_bullet.bullet_speed = bullet_speed
|
||||||
instance_bullet.bullet_drop = gun.bullet_drop
|
instance_bullet.bullet_drop = bullet_drop
|
||||||
instance_bullet.random_spread_amt = gun.random_spread_amt
|
instance_bullet.random_spread_amt = random_spread_amt
|
||||||
instance_bullet.gun = gun
|
instance_bullet.gun = self
|
||||||
get_parent().add_child(instance_bullet)
|
get_parent().add_child(instance_bullet)
|
||||||
|
|
||||||
# Casing transform
|
# Casing transform
|
||||||
instance_casing = gun.casing.instantiate()
|
var instance_casing = casing.instantiate()
|
||||||
instance_casing.position = gun.casing_ejector.global_position
|
instance_casing.position = casing_ejector.global_position
|
||||||
instance_casing.transform.basis = gun.casing_ejector.global_transform.basis
|
instance_casing.transform.basis = casing_ejector.global_transform.basis
|
||||||
|
|
||||||
get_parent().add_child(instance_casing)
|
get_parent().add_child(instance_casing)
|
||||||
elif !gun.anim_player.is_playing():
|
elif !anim_player.is_playing():
|
||||||
gun.anim_player.play("empty")
|
anim_player.play("empty")
|
||||||
gun.audio_empty.play()
|
audio_empty.play()
|
||||||
|
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ func _physics_process(delta):
|
|||||||
|
|
||||||
# Shooting
|
# Shooting
|
||||||
if Input.is_action_pressed("shoot"):
|
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
|
var pos = Vector3.ZERO
|
||||||
pos.y = sin(time * BOB_FREQ) * BOB_AMP
|
pos.y = sin(time * BOB_FREQ) * BOB_AMP
|
||||||
pos.x = cos(time * BOB_FREQ / 2) * BOB_AMP
|
pos.x = cos(time * BOB_FREQ / 2) * BOB_AMP
|
||||||
print("hello")
|
|
||||||
return pos
|
return pos
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user