No Error, but the function isn't working

Godot Version: 4.2.2

Question

Hi I’m a brand new to Godot and programming. I’m making a top down shooter, but I can’t get the shoot function to work. The game runs perfectly fun, but pressing the fire key does nothing.

I set up the keybinds on the action map, Fire isn’t working despite every other keybind working.

Can you tell me where I went wrong?

Here is the script for the player

extends CharacterBody2D
@export var move_speed = 600.0

func get_input():
	var input_direction = Input.get_vector("move_left", "move_right", "move_up", "move_down")
	velocity = input_direction * move_speed

func mouse_look():
	look_at(get_global_mouse_position())
	
func _physics_process(delta):
	get_input()
	move_and_slide()

func shoot():
	const BULLET = preload("res://bullet.tscn")
	var new_bullet = BULLET.instantiate()
	new_bullet.global_position = %ShootingPoint.global_position
	%ShootingPoint.add_child(new_bullet)

	if Input.is_action_pressed("Fire"):
		shoot()```

**Here is the script for the bullet:**

```extends Area2D

@export var bullet_speed = 1000.0
@export var traveldistance = 0.0
@export var bullet_range = 1200.0

func _physics_process(delta):
	var direction = Vector2.RIGHT.rotated(rotation)
	position += direction * bullet_speed * delta
	
	traveldistance += bullet_speed * delta
	if traveldistance > bullet_range: 
		queue_free()```
	


func _on_body_entered(body):
	queue_free()
	if body.has_method ("take_damage"):
		body.take_damage()

You call the other ones move_left etc., is the action called Fire and not fire?

Yes it is capital F “Fire”

You’re checking for the “Fire” input inside the shoot() function. It only checks for the “Fire” input when shoot() is called, but it’s never called :slight_smile:

Put

if Input.is_action_pressed("Fire"):
		shoot()

inside either _process or _input

1 Like