- Edited
Hello, I am trying to instantiate several "bullets" around a scene and want them to form a circular shape around this scene.
My approach to doing this was that I would create a function in which I could decide;
- The scene to instantiate around (spawnerObject)
- Which scene to instantiate (bulletObject)
- How many scenes to instantiate (bulletAmount)
- At what speed the instantiated bullet scenes should move (bulletSpeed)
- How far away from the origin scene the instantiated bullet scenes should spawn (distanceFromSpawner)
This function is supposed to basically:
- Create a "bullet" scene
- Rotate itself by a certain amount (the amount is calculated by dividing 360 by the amount of bullets I need to instantiate)
- Repeat in a for loop until the specified amount of bullets have been instantiated.
I tried to explain it line by line in comments in the code so I hope that will be helpful.
Here is the script attached to the scene I use as the spawner object:
Here is the script attached to the bullet I'm trying to spawn:
Note: The bullet scenes do not collide with themselves.
The issue:
(Note: The purple orb is the bulletObject, the extremely small gray box with a star texture is the spawnerObject. Also note that none of these textures are mine and I have extracted them from Touhou 8 to serve as temporary textures to work with. Prettier than working with single colored boxes and circles, that's for sure)
If I input 1 to bulletAmount, it will instantiate the bullet where I want it to. That is good, it is supposed to do that:
If I input 5, it will spawn all of them at the same location and the spawnerObject's rotation is set to 0 degrees:
If I input an even number like 8 or 12, it will, again, spawn them at the same location. However, this time they would all spawn in the the opposite side and the rotation of the spawnerObject gets set to 180 degrees. I would expect at least the first of them to spawn 100 units below the spawnerObject but that is not the case (This picture is from when the input was 8):
If I input 7, it gets all messed up and spawns all of them at the same location, but the spawnerObject's rotation is set to -9 degrees:
I have absolutely no clue how and why any of this is happening. I've been stuck on this for the past 5 hours and finally decided to ask for help after googling the issue, browsing the documentation, and not being able to find anything helpful. Please tell me if there is any information missing that might be needed. I am extremely new to both coding and Godot so I might be missing something super obvious (which I kinda hope is the case lol). Thank you in advance