Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Composer3 |
I have added a custom mapping in the godot project settings called “shoot” and mapped it to the spacebar. I have my spaceship movement working with the arrow keys, and shooting also works, but when I hold down certain combinations of the arrow keys and the space bar, what I would expect to happen is for the spaceship to continue moving in the desired direction, and shoot while it is moving. Instead, it freezes as long as I am holding the spacebar, and when I release the spacebar, it continues to move but does not shoot.
Here is the script for the spaceship. If the script for the bullet is necessary as well, I will be happy to send it.
extends KinematicBody2D
var velocity = Vector2.ZERO
const SPEED = 250
var bullet_scn = preload("res://Bullet.tscn")
func _physics_process(delta):
var play_on = false
if Input.is_action_pressed('ui_down'):
velocity.y += SPEED
play_on = true
if Input.is_action_pressed('ui_up'):
velocity.y -= SPEED
play_on = true
if Input.is_action_pressed('ui_right'):
velocity.x += SPEED
play_on = true
if Input.is_action_pressed('ui_left'):
velocity.x -= SPEED
play_on = true
if Input.is_action_just_pressed('shoot'):
print("Shooting")
var bullet = bullet_scn.instance()
# bullet.position = get_global_position()
get_parent().add_child(bullet)
get_parent().move_child(bullet, 0)
if play_on:
$Sprite.play("on")
else:
$Sprite.play("idle")
move_and_slide(velocity)
velocity = Vector2.ZERO
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
func _on_Asteroid_body_entered(body):
pass