0 votes

To boil it down, I'm trying to make a bullet collide with a player every frame.
However, the situation is pretty complex, so I'll try to explain the structure here:

I have a general Battle scene:
enter image description here

There are multiple Encounter scenes.
One is chosen at the start of the battle, then added to CurrentEncounter:
enter image description here

The Encounter node has an Array[PackedScene].
Each PackedScene contains a Wave scene:
enter image description here

Here is a Wave. One is randomly chosen, then added to CurrentWave.
The Bullet node is the Area2D in question:
enter image description here


When the Wave loads, it instances the Player scene, then adds it as a child:

# Part of wave.gd

func _ready() -> void:
    # This is for debugging
    if get_tree().current_scene == self:
        setup()
        start()

func setup() -> void:
    # Called IMMEDIATELY after instancing
    rect_min_size = rect_size
    _create_bounds()


func start() -> void:
    # Called when the player should spawn
    player = SCENE_SOUL.instance()
    add_child(player)
    player.owner = self
    player.position = get_node("PlayerSpawn").position

To collide with the player (KinematicBody2D), the Bullet has this:

# Part of bullet.gd
extends Area2D

# ...

onready var wave: Wave = owner

# ...

func _physics_process(delta: float) -> void:
    if wave.soul in get_overlapping_bodies():
        wave.soul.damage(at)

And here's how the Wave is loaded in Battle:

# Part of one of Battle's children

func enter() -> void:
    var next_wave = battle.encounter.get_wave()
    next_wave.setup()
    battle.current_wave.add_child(next_wave)

    battle.anim.play("show arena")
    yield(battle.anim, "animation_finished")

    next_wave.start()

With that out of the way, here's the problem:

When I run the Wave scene by itself, everything works as expected.
But when I test it in the Battle scene, the Bullet just doesn't collide with the Player.

(The Bullet's and Player's collision layers and masks are compatible.)

Below is a list of things I've tried, while getting the same results:
- Replacing wave.soul in get_overlapping_bodies() with overlaps_body(wave.soul)
- Using signals

Godot version v3.5
in Engine by (21 points)

For the record, in the case where it didn't work, the Player can still collide with physics bodies, just not the Area2D

1 Answer

0 votes
Best answer

Ok I figured it out!
It's because, during battle, the game is paused (so nothing in the overworld is processed)

The Battle scene's pause_mode property is set to PROCESS, so it's not affected by the pause. (everything else is INHERIT)

But apparently that means Area2D doesn't check for collision. Weird...

I guess I never noticed because, when I made the Bullet move through _physics_process(), it moved normally

by (21 points)
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.