![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Xalian |
can someone help me on how to create a projectile?
Currently, the projectile when pressed tab “shoots out” and goes to the right properly but not in the location respective of the player. It only shoots from one point on the map. I want it to be able to follow the player and wherever he is to shoot from there. How do I do this?
The code at the bottom of actionpressed is where I need help. As you can see, when I comment out that line of code the fireball appears and goes to the right in a set position on screen. But I want it to come out of my player depending on the players position, so I added in the (hashtagged out) line of code but when I do so the fireball does not appear.
func _physics_process(delta):
if Input.is_action_pressed("ui_right"):
velocity.x = SPEED
$AnimatedSprite.play("run")
$AnimatedSprite.flip_h = false
elif Input.is_action_pressed("ui_left"):
velocity.x = -SPEED
$AnimatedSprite.play("run")
$AnimatedSprite.flip_h = true
else:
velocity.x = 0
if on_ground == true:
$AnimatedSprite.play("idle")
if Input.is_action_pressed("ui_up"):
if on_ground == true:
velocity.y = JUMP_POWER
on_ground = false
if Input.is_action_just_pressed("ui_focus_next"):
var fireball = FIREBALL.instance()
get_parent().add_child(fireball)
#fireball.position = $Position2D.global_position