This is the testing Godot forums! All forum posts unique to this forum will be deleted! Please use the main forums here for any posts you want to keep. All forum rules still apply.

Help with bug on Godot First Game

weddi_eddyweddi_eddy Posts: 9Member

Hello. I've followed the Your First Game ( tutorial to a T and for the most part, it works however there is one weird bug I've noticed that I can't quite figure out.

The Mob should be created offscreen following the PathFollow2D node and for the top, left and right parts of the path, it works perfectly. For the bottom however, mobs are created about midway up the screen (almost like they appear out of thin-air). The player can hang out in the bottom and avoid most of the mobs unless they spawn from the top.

I've been trying to figure out why this happens but I can't. I've tried resizing and redrawing the Path2D but the same thing happens. Any idea on what might be happening here or a way I can troubleshoot this?


  • mr_moonmr_moon Posts: 49Member

    Can I see your code?

  • weddi_eddyweddi_eddy Posts: 9Member
    edited April 2020

    Sure thing! Here it is:

    extends Node
    export (PackedScene) var Mob
    var score
    func _ready():
    # Declare member variables here. Examples:
    # var a = 2
    # var b = "text"
    func game_over():
    func new_game():
        score = 0
        $HUD.show_message("Get Ready")
    func _on_MobTimer_timeout():
        # Choose a random location on Path2D.
        $MobPath/MobSpawnLocation.offset = randi()
        # Create a Mob instance and add it to the scene.
        var mob = Mob.instance()
        # Set the mob's direction perpendicular to the path direction.
        var direction = $MobPath/MobSpawnLocation.rotation + PI / 2
        # Set the mob's position to a random location.
        mob.position = $MobPath/MobSpawnLocation.position
        # Add some randomness to the direction.
        direction += rand_range(-PI / 4, PI / 4)
        mob.rotation = direction
        # Set the velocity (speed & direction).
        mob.linear_velocity = Vector2(rand_range(mob.min_speed, mob.max_speed), 0).rotated(direction)
        #mob.linear_velocity = mob.linear_velocity.rotated(direction)
        $HUD.connect("start_game", mob, "_on_start_game")
    func _on_ScoreTimer_timeout():
        score += 1
    func _on_StartTimer_timeout():
  • weddi_eddyweddi_eddy Posts: 9Member

    I've compared the code from to my code and apart from the comments and the addition of music and sounds, it all seems the same.

  • mr_moonmr_moon Posts: 49Member

    did you check the window size under project settings?

  • weddi_eddyweddi_eddy Posts: 9Member

    Hey! I figured it out! So, the MobPath Path2d was scaled and not set to 1,1. The scale caused it to seem like it was the full window size but it wasn't. Once I changed the y scale back to 1, it showed me a path that looked oddly similar to where the mobs were spawning. I resized the Path2d and the 1,1 scale remained.

    I ran the game and it worked like a charm! Thank you for your help! Your questions may not have lead me to figure this out.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.