(Godot) Touch does not perform arc animation and does not work properly

Asked

Viewed 106 times

0

Hello,

I’m a multimedia student and I’m working on my Professional Aptitude Test.

For this I decided to create a 2D RPG Zelda-like Game (for Android devices). For this I have used the Godot platform that makes use of Gdscript (Python derived language itself, optimized for games).

I have a whole player interface created, which has some small bugs.

When clicking the button to shoot, the player should start a small animation and only then the arrow would be created, for the moment, the player just shoots the arrow and jumps the whole animation.

func get_attack_input():
if Input.is_action_pressed("ui_accept") and not charging_bow and can_shoot || attack and not charging_bow and can_shoot:
    charging_bow = true
    velocity = Vector2.ZERO
    sprite.play("Attack_Bow")
    tween.interpolate_property(self, "bow_power", 3, 8, 5, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
    tween.start()
elif Input.is_action_just_released("ui_accept") and can_shoot || attack and can_shoot:
    charging_bow = false
    tween.stop(self, "bow_power")
    sprite.play("Idle")
    var arrow_instance = arrow.instance()
    var direction = -1 if sprite.flip_h else 1
    arrow_instance.init(direction, bow_power)
    get_parent().add_child(arrow_instance)
    arrow_instance.global_position = global_position
    arrow_instance.global_position.x += 16 * direction
    bow_power = 0
    print("Shoot")
    
    #Optimize Arrow
    if get_tree().get_nodes_in_group("arrows").size() >= 3:
        for arrow in get_tree().get_nodes_in_group("arrows"):
            arrow.queue_free()
            print("deleted arrows")

    #Disable Shoot
    can_shoot = false
    
    #Start Timer
    timer.start()
  • I don’t know much about Python or Godot Engine, but there is not a missing indentation in all the lines after defining the function (first line)?

  • where you got the function get_tree()?

  • I reversed the question to the original version and changed the tag to [tag:Godot]

1 answer

1

You need to use the Yield function for the code only to continue when the animation is finished so there are no jumps, you can find in the Godot documentation.

your code would look like this

func get_attack_input():
    if Input.is_action_pressed("ui_accept") and not charging_bow and can_shoot | attack and not charging_bow and can_shoot:
        charging_bow = true
        velocity = Vector2.ZERO
        sprite.play("Attack_Bow")
        yield($sprite,"animation_finished") ##### AQUI AQUI AQUI AQUI 
        tween.interpolate_property(self, "bow_power", 3, 8, 5, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
        tween.start()
    elif Input.is_action_just_released("ui_accept") and can_shoot | attack and can_shoot:
        charging_bow = false
        tween.stop(self, "bow_power")
        sprite.play("Idle")
        arrow_instance = arrow.instance()
        direction = -1 if sprite.flip_h else 1
        arrow_instance.init(direction, bow_power)
        get_parent().add_child(arrow_instance)
        arrow_instance.global_position = global_position
        arrow_instance.global_position.x += 16 * direction
        bow_power = 0
        print("Shoot")


#Optimize Arrow
if get_tree().get_nodes_in_group("arrows").size()>=3:
    for arrow in get_tree().get_nodes_in_group("arrows"):
        arrow.queue_free()
        print("deleted arrows")

#Disable Shoot
can_shoot = false

#Start Timer
timer.start()

You can see more about the Yield function in the documentation https://docs.godotengine.org/pt_BR/stable/getting_started/scripting/gdscript/gdscript_basics.html

  • Thank you for trying to help, unfortunately the question was marked wrong and it is NOT a Python language problem, the problem is Godot Engine language. For this reason it is worth checking if your answer is according to the problem presented. = D

  • 1

    @Icaromartins arranging the "def" and the ( ) in if may even remain a valid Godot Engine code. It may have been just "force of habit" :)

  • 1

    I was wrong to put def instead of func but the code works, I will edit and put referencas,

Browser other questions tagged

You are not signed in. Login or sign up in order to post.