Skip to content

Commit

Permalink
Fix rifle firing, prevent it when reload animation is playing
Browse files Browse the repository at this point in the history
and prevent player from shoot in the foot by excluding it in raycast.
  • Loading branch information
mrezai committed Jul 11, 2024
1 parent 10c71a7 commit 68525cf
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions COGITO/Wieldables/wieldable_laser_rifle.gd
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ var spawn_node : Node
var is_firing : bool = false

var firing_cooldown : float
var player_rid : RID

var inventory_item_reference : WieldableItemPD


func _ready():
wieldable_mesh.hide()
firing_cooldown = 0
player_rid = CogitoSceneManager._current_player_node.get_rid()


func _physics_process(_delta: float) -> void:
Expand All @@ -38,6 +40,8 @@ func _physics_process(_delta: float) -> void:

if is_firing:
if firing_cooldown <= 0:
if animation_player.is_playing():
return
# Gettting camera_collision pos from player interaction component:
var _camera_collision = player_interaction_component.Get_Camera_Collision()
hit_scan_collision(_camera_collision) #Do the hitscan
Expand Down Expand Up @@ -83,6 +87,7 @@ func action_secondary(is_released:bool):
func hit_scan_collision(collision_point:Vector3):
var bullet_direction = (collision_point - bullet_point.get_global_transform().origin).normalized()
var new_intersection = PhysicsRayQueryParameters3D.create(bullet_point.get_global_transform().origin, collision_point + bullet_direction * 2)
new_intersection.exclude = [player_rid]

var bullet_collision = get_world_3d().direct_space_state.intersect_ray(new_intersection)

Expand Down

0 comments on commit 68525cf

Please sign in to comment.