0 votes

I have an enemy that spews out area2ds as projectiles (toxic clouds) if they remain a child of the enemy. If I set them as a child of the main screen, they disappear (and performance takes a big hit for some reason).

    var c = cloud.instance()
c.transform = $Fans.transform

var target = get_parent()
target.add_child(c)

I've also tried the following to get the parent node with the same results.

var target = get_tree().get_root().get_node("MainScreen")

If I print out "target" it shows me the MainScreen node in both cases.
If I just leave the area2ds as a child of the enemy, they don't collide with the player.
Any of that make sense?

Godot version 3.4.1
in Engine by (15 points)

1 Answer

+1 vote
Best answer

Your main screens surely has transform origin of Vector(0,0), or - if it doesn't inherit Node2D/Spatial - has no position property at all. That makes all of your projectiles spawn in one point, on the left corner of the screen, propably not visible to You. I bet frame drops because projectiles amassed in one point collide with each other endlessly.
Sollution is to manually set global position of bullets before You add them as a child of main screen ( provided, that bullets handle rest of the movement by themselves )
No collision with player is a different problem. Make sure to properly set collision layers and masks.

by (5,132 points)
selected by

I eventually figured out that the position needed to be set. It's a little wonky because they seem to build up in one spot and then start moving. Because they're clouds, I mask that by setting the sprite as visible a split second after being assigned. The main screen is a node2d so I'm not sure why it doesn't inherit. Is there a proper way to set that up?
I also figured out the collision issues, yes they were unrelated to the parenting. I'm still very new to this architecture so I'm learning what all the signals do.

If it is Node2D, then it does have position property and passes it to its children. But position only indicates origin point of a node in space. So even if your screen is a large rectangle covering viewport it still has tiny origin, which is 0,0 by default. Adding children to screen sets their position to screens origin. Enemies on the other hand are represented by small sprites, and their position is easier to imagine. Adding child to enemy will add it close to its Sprite origin. Still it is much better to add bullets as child of screen, otherwise they will be moving along enemies and be prone to enemies transforms.

Projectiles have slow start ? Perhaps they are instanced too fast, on top of each other ? You need to set their collision so they don't collide with themselves

Thanks for the info.

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 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 webmaster@godotengine.org with your username.