Mouse Button not working while action held

Godot Version

4.6-stable

Question

Hello, I’m trying to implement a slide mechanic, however while 'I’m holding the slide key(ctrl) I am no longer able to shoot(Mouse 1). If I hold shoot before sliding the shooting works however if I attempt to shoot while sliding nothing happens.

Slide Class

extends State
class_name Player_Slide

var time = 0

func Physics_Update(delta:float):
	if(entity):
		var input_dir = Input.get_vector("move_left","move_right","move_forward","move_back")
		var direction = (entity.transform.basis * Vector3(input_dir.x, 0 ,input_dir.y)).normalized()
		
		entity.velocity.x = direction.x  * delta * slide_impulse.sample(time)
		entity.velocity.z = direction.z * delta * slide_impulse.sample(time)
		time += delta
		entity.model.rotation.x = 45
		
		if not entity.is_on_floor():
			entity.velocity.y = entity.velocity.y - (fall_acceleration )

		entity.move_and_slide()
		print(time)
		
		if Input.is_action_just_released("slide"):
			Transitioned.emit(self,"Player_Move")
			time = 0
			

		if Input.is_action_pressed("jump"):
			Transitioned.emit(self,"Player_Jump")
			time = 0

Shoot Class

extends Marker3D
class_name Bullet_Path

@onready var bullet_pivot:Marker3D = $"."
@onready var bullet_path:RayCast3D = $Bullet_Path
@onready var cooldown:Timer = $Shot_Cooldown
var can_shoot:bool = true
@export var sensitivity:float = 0.5
@export var bullet:PackedScene
var bullet_dir:Vector3
var bullet_object:Bullet

func _input(event):
	if event is InputEventMouseMotion:
		bullet_pivot.rotate_x(deg_to_rad(-event.relative.y *sensitivity))
		bullet_pivot.rotation.x = clamp(bullet_pivot.rotation.x,deg_to_rad(-30),deg_to_rad(30))

func _physics_process(_delta):
	if Input.is_action_pressed("shoot") and can_shoot:
		primary_fire()

func primary_fire():
	cooldown.wait_time = 0.5
	create_bullet()
	begin_cooldown()

func create_bullet():
	bullet_dir = (bullet_path.to_global(bullet_path.target_position) - bullet_path.to_global(Vector3.ZERO)).normalized()
	bullet_object = bullet.instantiate().duplicate()
	get_parent().get_node("%Projectiles").add_child(bullet_object)
	bullet_object.pass_direction(bullet_path.global_position,bullet_dir)


func _on_shot_cooldown_timeout():
	can_shoot = true

func begin_cooldown():
	can_shoot = false
	cooldown.start()

Thank you for any assistance.

You have a bug somewhere in your code. Use debugger breakpoints and print statements across your code to monitor where the execution is going and what are the values of relevant variables. When you locate something that doesn’t match the expectations, you’re likely near the cause of the bug.

2 Likes

gotcha ill go ahead and try that

1 Like

Maybe, the shoot mecanic get override by the slide Input.

So calculate the mouse/joystick/direction of the player when you shoot and don’t verify it for all input.

Make a copy of your code and try that way.

Turns out the code is just busted if CTRL is used as a the key for sliding but works for every other input. It’s likely my own keyboard issue or a mac issue. Thanks for the help everyone.

maybe it’s an issue with keyboard ghosting? (when the keyboard can’t detect multiple keys held down)

I thought that as well but after testing my keyboard with a tester it seemed fine handling all the key presses. In addition when I switched the key from control to a different key everything worked fine. So I’m kinda stumped about whats wrong so I’m just using a different key for now.

On a Mac it could be that CTRL and left click is interpreted as a right click (Right-click on Mac – Apple Support (UK))

1 Like

Oh my gosh i completely forgot about that. Thank you!

1 Like