Godot Version
Godot 4.7
Question
Hello There,
It’s Acelon
I’m Making A 3D Game Where Some Of The Enemies Are 2D And I Need Them To Be Spawned/Instantiated On My Screen At A Random Position At A Random Interval Of Time
There Are 5 - 6 Of These Enemies That I Have Made Whose Scene Tree Goes Like This i.e, Node2D → Sprite2D (For Now)
Now, I Want To Spawn Them On My Screen At A Random Position Which I Can Achieve Using Path2D Node And PathFollow2D Node
Now, The Main Doubt That I’m Facing Is That How Do I Spawn Them??
Should I Write The Codes Inside The Player Script And Instantiate Them There
OR
Should I Make An Entirely New Global Script Solely For The Purpose Of Instantiating And Managing These Enemies (As EnemyManager.gd)
Making It Global Might Also Make It Easier For Me To Apply Conditions To Them And Introduce New Elements Without Any More Problem
What Should I Do???
I Asked AI Just For Some Clarity But It Told Me To Use 3D Nodes To Spawn And Manage Them Which IDK If Will Work
Pls Do Tell Me And Give Any Advice If Possible
All The Suggestion And Solutions Are Highly Appreciated,
Acelon
Capitalizing every word makes it surprisingly difficult to read.
Your 2D nodes are probably not going to interact with anything 3D, not without a lot of code to bridge the gap. It’s very likely it would be better to use only 3D with sprites/billboards.
Maybe if you explain more about what you hope to achieve, like a design document and what you have so far, we could help more.
Sorry for the unnecessary capitalisation, I’ll keep it minimum
So, what I’ve been trying to do is that these sprites would appear on the screen for a certain amount of time during which, you have to do the objectives that each of the enemy gives or else your health goes 0 And you’ll die
No physical contact or any type of action they’ll appear, provide objective and stay there until the time runs out in which case I’ll queue free then
There are lots of ways to achieve this, and which approach you take will depend on several factors. The first one that comes to my mind will work if the enemies are nothing but sprites that all do the same thing. You can create a class with a 2D array/table. Each array entry is an array of data (sprite, dialogue, time on screen, spawn locations, path, etc) for an enemy. The object will be responsible for enemy spawn timing and instantiation, and is spawned into your game scene when the game begins.
I’m thinking of different enemies with different behaviours
For Ex:
- The first enemy when appears, requires you to crouch down and stop moving
- the second enemy tells you to change your direction according to him
- The third enemy requires you to slide and not run nor crouch
- The fourth enemy tells you to not be on floor while it’s active
Here Are some concept enemies that i saw and am thinking to add to my game
here, the similarity is that they’ll instantiate every given period of time or when i enter a room randomly and have different appearance (Sprite2D, Texture) and will move in different ways
Some may move across your screen
Will your given method work for this???
It could work if the required player behaviors aren’t enforced, but I would probably create a base class from which all enemies inherit (and which contains all common functions and data), and differentiate all the enemies in their own subclasses.
Can you show a visual mockup of how is this supposed to look?
Here’s The Video
For Now I have made only one (Cuz my art sucks)
I’ll Make some more later
This enemy, if you don’t look up, will damage you
Sorry, If I’m making y’all confused or something
I’m pretty new to these stuffs, so sorry If I’m being a dumbass 
Is that enemy supposed to be positioned in 3D space? If that’s the case, just use a 3D sprite.
No, It’ll be a 2D sprite
Look at the tree of the enemy scene, it’s just going to appear on your screen
Like how your healthbar or staminabar or any other ui elements show up on screen (having no relation with the physical world)
Where’s the problem then? Make a 2D sprite and place it wherever it needs to be on the screen.
I know and I’m Trying
I’m just not sure how to
IDK much about using classes
That’s why I was thinking to make an entirely new script for these enemies and make it global and autoload
What would be the good approach for these kinds of enemies???
Same as 3D enemies. Make a scene that represents the enemy and instantiate it when the enemy is supposed to appear. The scene can contain the main sprite, related gui elements and a script attached to the top node that implements enemy’s bevior/logic.
These enemies behavior are going to be coded in the enemy scene itself
What I’m thinking is that if i make A global script where i store all these enemies scenes in an array and handle their spawn randomly in a period of time or by some other condition
But if y’all say to use classes, I’ll study on that
That’s a good approach.
Not sure what you mean by “classes”. Every script you write is a class, including autoloaded scripts.
IDK that much about classes so I’ll be using global scripts
A class is just a collection of variables and functions that are put into a single file and are supposed to work together.
Global script is a class as well. Every gdscript source code file is in fact a class.
There is also another topic made by where I talked about the animation player bug and have written all the details abt it
Pls, if you have time check it out and provide me any suggestion is possible