diff --git a/scripts/breakable.gd b/scripts/breakable.gd index 820bf55..2313889 100644 --- a/scripts/breakable.gd +++ b/scripts/breakable.gd @@ -1,8 +1,10 @@ extends RigidBody3D @export var broken_object : Resource +@export var break_velocity : float = 10 var break_on_land : bool = false +var held_currently : bool = false # Called when the node enters the scene tree for the first time. func _ready(): @@ -11,7 +13,7 @@ func _ready(): # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): - if linear_velocity.length() >= 10: + if linear_velocity.length() >= break_velocity and !held_currently: break_on_land = true func breaking(current_velocity): diff --git a/scripts/bullet.gd b/scripts/bullet.gd index 98d9341..baf15ae 100644 --- a/scripts/bullet.gd +++ b/scripts/bullet.gd @@ -36,7 +36,7 @@ func _physics_process(delta): if ray.is_colliding(): var body = ray.get_collider() - if !body.is_in_group("player"): + if body != null and !body.is_in_group("player"): mesh.visible = false ray.enabled = false diff --git a/scripts/player.gd b/scripts/player.gd index 7fbb4a7..b3a3380 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -301,7 +301,7 @@ func _physics_process(delta): gun.anim_player.play("swap_out") level_control.gun_spawn(level_control.current_gun_index + 1) else: - held_item_rotation.y += deg_to_rad(45) + held_item_rotation.y = clamp(held_item_rotation.y + deg_to_rad(45), deg_to_rad(0),deg_to_rad(360)) #Weapon Swap Down if Input.is_action_just_pressed("scroll_down") and !gun.anim_player.is_playing(): @@ -310,7 +310,7 @@ func _physics_process(delta): gun.anim_player.play("swap_out") level_control.gun_spawn(level_control.current_gun_index - 1) else: - held_item_rotation.y -= deg_to_rad(45) + held_item_rotation.y = clamp(held_item_rotation.y - deg_to_rad(45), deg_to_rad(0),deg_to_rad(360)) # Weapon Swap by Numbers if Input.is_action_just_pressed("numb_1"): @@ -333,20 +333,6 @@ func _physics_process(delta): weapon_select(8) if Input.is_action_just_pressed("numb_0"): weapon_select(9) - - # Move Held Items - if held_item != null: - var held_force_dir = moveable_holder.global_position - held_item.global_position - held_item.set_constant_force(held_force_dir * 30) - held_item.rotation = held_item_rotation #lerp(held_item.rotation, held_item_rotation, delta * 30) - - #break when moved too far away - var distance_from_player = abs(self.global_position - held_item.global_position) - if distance_from_player.length() > 5: - release_moveable() - if stand_check.is_colliding(): - if stand_check.get_collider() == held_item: - release_moveable() #interact button if Input.is_action_just_pressed("interact"): @@ -376,6 +362,7 @@ func _physics_process(delta): if level_control.health <= 0: level_control.die() + hold_item() move_and_slide() weapon_tilt(input_dir.x, delta) weapon_sway(delta) @@ -459,18 +446,33 @@ func grab_moveable(body): held_item_gravity_cache = body.gravity_scale held_item_mass_cache = body.mass #change rigidbody settings - body.linear_damp = 5 - body.angular_damp = 5 + body.linear_damp = 0 #5 + body.angular_damp = 0 #5 body.mass = 1 held_item.gravity_scale = 0 - + +func hold_item(): + # Move Held Items + if held_item != null: + var held_dir = moveable_holder.global_position - held_item.global_position + var held_av = held_item_rotation - held_item.rotation + held_item.linear_velocity = held_dir * 30 + held_item.angular_velocity = held_av * 10 + + #break when moved too far away + var distance_from_player = abs(self.global_position - held_item.global_position) + if distance_from_player.length() > 5: + release_moveable() + if stand_check.is_colliding(): + if stand_check.get_collider() == held_item: + release_moveable() + func release_moveable(): held_item_rotation = Vector3(0,0,0) held_item.gravity_scale = held_item_gravity_cache held_item.linear_damp = held_item_linear_damp_cache held_item.angular_damp = held_item_angular_damp_cache held_item.mass = held_item_mass_cache - held_item.set_constant_force(Vector3(0,0,0)) held_item = null func hit(damage, fired_by, target_type):