This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Hi I have a world scene and an enemy scene. The enemy scene is being instanced inside the world scene through codes. My code goes this way:

    var enemygen = enemy.instance()
    if (summon == false):

     summon = true
     summon_count = summon_count + 1


     var epos = Vector2(500, 50) + get_node("spawnpoint/pipe").get_pos()
     enemygen.set_pos(epos)
     get_parent().add_child(enemygen)
     en_timer.start()

What it does is basically spawning the enemy scene from the right side because that is what my enemy scene's default direction is. Now, what I want for it to happen is for every other spawn, the enemy will move left. Is there anyway to tweak the instanced scenes movement? tried tweaking with singleton but no luck so far. Thank you in advance

in Engine by (45 points)

How many enemies do you need to spawn and how often (time elapsed between 2 enemy spawns)?

1 Answer

+1 vote

Yes. Attach a script to the enemy scene's root node, and write your own function or functions for controlling movement. Perhaps move_left() or move_right() or something multipurpose like move(direction).

A basic example for alternating calls. Using a helper function for odd and even numbers:

func is_even(num): return num % 2 == 0 // A function for alternating.

Then call the enemy functions.

if(is_even(summon_count)): enemy.move_left()
else: enemy.move_right()
by (5,286 points)

Hello aven. Thanks for the reply :). I have this code right now, and i did a print check of whether the image is flipped or not. Apparently it says that current instanced node is flipped but it doesn't when i run it. Did i miss something? everything seems to be in order.

    if (summon == false):

     summon = true
     summon_count = summon_count + 1
     var mod = summon_count%2
     var enemygen = enemy.instance()
     if (mod > 0):

      enemygen.get_node("Sprite").set_flip_h(true)
      print (enemygen.get_node("Sprite").is_flipped_h())

    var epos = Vector2(500, 50) + get_node("spawnpoint/pipe").get_pos()
    enemygen.set_pos(epos)
    get_parent().add_child(enemygen)

I can't reproduce it, so you might want to test other assumptions. Like what node is it selecting?

var node = enemygen.get_node("Sprite")
printt(node.get_name(), node.get_type())
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.