generated from krampus/template-godot4
Prevent tool from auto-firing after object is thrown
This commit is contained in:
parent
667aa38cda
commit
24d34235ee
@ -28,6 +28,9 @@ const THROW_TUTORIAL_DELAY := 6.0
|
|||||||
## Temporary collision mask.
|
## Temporary collision mask.
|
||||||
@export_flags_3d_physics var hold_collision_physics := 0b01000001
|
@export_flags_3d_physics var hold_collision_physics := 0b01000001
|
||||||
|
|
||||||
|
## This is set when an object is thrown and released when the mouse button is released
|
||||||
|
var just_threw_object := false
|
||||||
|
|
||||||
## The object currently being held.
|
## The object currently being held.
|
||||||
var _held_object: RigidBody3D
|
var _held_object: RigidBody3D
|
||||||
|
|
||||||
@ -108,6 +111,7 @@ func _process_hold_controls() -> void:
|
|||||||
drop()
|
drop()
|
||||||
elif Input.is_action_just_pressed("fire"):
|
elif Input.is_action_just_pressed("fire"):
|
||||||
throw()
|
throw()
|
||||||
|
just_threw_object = true
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(delta: float) -> void:
|
func _physics_process(delta: float) -> void:
|
||||||
@ -115,6 +119,10 @@ func _physics_process(delta: float) -> void:
|
|||||||
if holding_object():
|
if holding_object():
|
||||||
_process_hold_controls()
|
_process_hold_controls()
|
||||||
|
|
||||||
|
# Release held object lockout as soon as possible
|
||||||
|
if not Input.is_action_pressed("fire"):
|
||||||
|
just_threw_object = false
|
||||||
|
|
||||||
# Held object logic
|
# Held object logic
|
||||||
if not holding_object():
|
if not holding_object():
|
||||||
return
|
return
|
||||||
|
@ -216,7 +216,8 @@ func _physics_process(delta: float) -> void:
|
|||||||
firing = false
|
firing = false
|
||||||
if tool:
|
if tool:
|
||||||
# Tool use
|
# Tool use
|
||||||
if Input.is_action_pressed("fire"):
|
# Lockout fire input after throwing an object until input is released.
|
||||||
|
if Input.is_action_pressed("fire") and not hold_component.just_threw_object:
|
||||||
tool.fire()
|
tool.fire()
|
||||||
firing = true
|
firing = true
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user