casings integrate player velocity, can't pick up already held guns
This commit is contained in:
@@ -7,6 +7,7 @@ extends RigidBody3D
|
||||
var rng = RandomNumberGenerator.new()
|
||||
var random_rotation = true
|
||||
var particle_number
|
||||
var player_velocity
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
@@ -22,7 +23,7 @@ func _ready():
|
||||
var av_y = rng.randf_range(-50.0,50.0)
|
||||
var av_z = rng.randf_range(-50.0,50.0)
|
||||
|
||||
linear_velocity += transform.basis * Vector3(lv_x, lv_y, lv_z)
|
||||
linear_velocity += transform.basis * Vector3(lv_x, lv_y, lv_z) + player_velocity
|
||||
angular_velocity += transform.basis * Vector3(av_x,av_y,av_z)
|
||||
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ const DEAD_CAM_FOV = 50.0
|
||||
|
||||
var focus_dist
|
||||
var target : Node
|
||||
var focus_target
|
||||
var respawn_position
|
||||
var respawn_rotation
|
||||
var taunt_node
|
||||
@@ -64,12 +63,6 @@ func _ready():
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
if target != null:
|
||||
focus_dist = camera.global_position.distance_to(target.global_position)
|
||||
else:
|
||||
focus_dist = 10.0
|
||||
camera.attributes.dof_blur_far_distance = focus_dist + 8
|
||||
camera.attributes.dof_blur_near_distance = focus_dist - 2
|
||||
|
||||
if target == null:
|
||||
anim_step = 3
|
||||
@@ -79,6 +72,7 @@ func _process(delta):
|
||||
match anim_step:
|
||||
0:
|
||||
#Show enemy that killed player
|
||||
focus_on_target(target)
|
||||
var target_pos_adjusted = Vector3(target.position.x -4,target.position.y + 4,target.position.z -4)
|
||||
cam_target.global_position = lerp(cam_target.global_position,target_pos_adjusted,delta * MOVE_SPEED)
|
||||
look_ray.global_position = target_pos_adjusted
|
||||
@@ -87,6 +81,7 @@ func _process(delta):
|
||||
camera.fov = lerp(camera.fov, 40.0, delta * 5)
|
||||
1:
|
||||
#aim at player from enemy
|
||||
focus_on_target(level_control.player)
|
||||
Engine.time_scale = .05
|
||||
AudioServer.set_bus_effect_enabled(0,0,true)
|
||||
taunt_node.visible = false
|
||||
@@ -110,3 +105,11 @@ func _on_timer_timeout():
|
||||
|
||||
func reload_level():
|
||||
get_tree().reload_current_scene()
|
||||
|
||||
func focus_on_target(focus_target):
|
||||
if target != null:
|
||||
focus_dist = camera.global_position.distance_to(focus_target.global_position)
|
||||
else:
|
||||
focus_dist = 10.0
|
||||
camera.attributes.dof_blur_far_distance = focus_dist + 8
|
||||
camera.attributes.dof_blur_near_distance = focus_dist - 2
|
||||
|
||||
@@ -124,6 +124,7 @@ func spawn_casing():
|
||||
var instance_casing = casing.instantiate()
|
||||
instance_casing.position = casing_ejector.global_position
|
||||
instance_casing.transform.basis = casing_ejector.global_transform.basis
|
||||
instance_casing.player_velocity = player.velocity * transform.basis
|
||||
get_tree().get_root().add_child(instance_casing)
|
||||
|
||||
func bullet_fire():
|
||||
|
||||
@@ -177,6 +177,7 @@ func spawn_casings():
|
||||
instance_casing.position = i.global_position
|
||||
instance_casing.random_rotation = false
|
||||
instance_casing.transform.basis = i.global_transform.basis
|
||||
instance_casing.player_velocity = player.velocity * transform.basis
|
||||
instance_casing.rotation.x += deg_to_rad(90)
|
||||
instance_casing.linear_velocity.y = -(8 + rng.randf_range(0,3))
|
||||
get_tree().get_root().add_child(instance_casing)
|
||||
|
||||
@@ -138,39 +138,12 @@ func _on_area_3d_body_part_hit(dam,bullet_damage):
|
||||
|
||||
func _on_prefire_timer_timeout():
|
||||
#barrel 1 fire
|
||||
var instance_bullet = bullet.instantiate()
|
||||
instance_bullet.position = barrel_1.global_position
|
||||
instance_bullet.transform.basis = barrel_1.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.bullet_damage = bullet_damage
|
||||
instance_bullet.fired_by = self
|
||||
get_tree().get_root().add_child(instance_bullet)
|
||||
|
||||
fire(barrel_1)
|
||||
#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.bullet_speed = bullet_speed
|
||||
instance_bullet2.bullet_drop = bullet_drop
|
||||
instance_bullet2.random_spread_amt = random_spread_amt
|
||||
instance_bullet2.bullet_damage = bullet_damage
|
||||
instance_bullet2.fired_by = self
|
||||
get_tree().get_root().add_child(instance_bullet2)
|
||||
fire(barrel_2)
|
||||
|
||||
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)
|
||||
|
||||
audio_fire.play()
|
||||
|
||||
prefire_timer.stop()
|
||||
postfire_timer.start()
|
||||
|
||||
@@ -192,3 +165,22 @@ func _on_knocked_timer_timeout():
|
||||
func _on_stunned_timer_timeout():
|
||||
print("STUN TIMEOUT")
|
||||
stunned = false
|
||||
|
||||
func fire(barrel):
|
||||
var instance_bullet = bullet.instantiate()
|
||||
instance_bullet.position = barrel.global_position
|
||||
instance_bullet.transform.basis = barrel_1.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.bullet_damage = bullet_damage
|
||||
instance_bullet.fired_by = self
|
||||
get_tree().get_root().add_child(instance_bullet)
|
||||
audio_fire.play()
|
||||
spawn_casing()
|
||||
|
||||
func spawn_casing():
|
||||
var instance_casing = casing.instantiate()
|
||||
instance_casing.position = casing_ejector.global_position
|
||||
instance_casing.transform.basis = casing_ejector.global_transform.basis
|
||||
instance_casing.player_velocity = velocity * transform.basis
|
||||
|
||||
@@ -7,6 +7,7 @@ extends RigidBody3D
|
||||
@onready var level_control = get_tree().current_scene
|
||||
|
||||
var pickupable = true
|
||||
var gun_already_held = false
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
@@ -18,11 +19,16 @@ func _process(delta):
|
||||
pass
|
||||
|
||||
func picked_up():
|
||||
level_control.held_guns.append(gun_resource)
|
||||
var instance_gun = gun_resource.instantiate()
|
||||
level_control.ammo_current.append(instance_gun.max_ammo)
|
||||
level_control.ammo_reserve.append(instance_gun.max_ammo * instance_gun.start_mags)
|
||||
var weapon_id = level_control.held_guns.size() - 1
|
||||
level_control.player.gun.anim_player.play("swap_out")
|
||||
level_control.gun_spawn(weapon_id)
|
||||
for i in level_control.held_guns:
|
||||
if i == gun_resource:
|
||||
gun_already_held = true
|
||||
|
||||
if !gun_already_held:
|
||||
level_control.held_guns.append(gun_resource)
|
||||
var instance_gun = gun_resource.instantiate()
|
||||
level_control.ammo_current.append(instance_gun.max_ammo)
|
||||
level_control.ammo_reserve.append(instance_gun.max_ammo * instance_gun.start_mags)
|
||||
var weapon_id = level_control.held_guns.size() - 1
|
||||
level_control.player.gun.anim_player.play("swap_out")
|
||||
level_control.gun_spawn(weapon_id)
|
||||
queue_free()
|
||||
|
||||
Reference in New Issue
Block a user