I’m currently testing out extensions and trying to see if I can get some things to work for a more serious project
In this case, I have 2 objects (Planetoids) with more objects (Orbits) orbiting around them. I want the game to pick a random orbit and shoot a bullet from it. I want this to happen with both planetoids so that both of their orbits can shoot at once
However in testing:
Here, only one planetoid’s orbit is actually shooting, and no matter how many times I reload the scene, the chosen orbit is the same one every single time
Here’s the code:
To reiterate, I want each planetoids’s orbits to shoot their own shots, and I want them to pick an orbit randomly. Can someone please tell me what I’m doing wrong?
If all orbitting objects are the same sprite then you need to limit the random pick to just the objects orbiting one planet at a time or use different objects. The pick a random object is picking from all of the orbiting objects.
The easiest fix would be to use different objects for the objects that are orbiting and then pick an object from each group separately.
I can see how that could be easiest, but it won’t be sustainable in the long run, especially if there are a whole lot of these placed in the scene, or if you want them to be spawned in dynamically.
Basically, if I have like an enemy with this behavior, would this imply that I need to create a new orbiting object for EVERY single individual orbiting enemy on the scene?
If possible, I would prefer to do this the hard way using the same objects. I would like to know how I can limit the random pick to JUST the objects orbiting around each planetoid.
Or is there no other way?
I don’t like this method that I’m going to suggest but it’s the only way I can think of doing it. Maybe, I’m being too strict. Normally, I would say create a link between the objects but the objects aren’t being created directly; the behavior is doing it. The behavior creates a link between the center objects and the orbiting objects. So, you can use that link to pick the orbiting objects using the take into account all orbitDummy linked to Planetoid before using the pick random object
I’m hesitant to suggest this because I would rather find a way to do it that doesn’t depend on the behavior. Extensions and behaviors are designed to be self-contained. I just don’t think it’s best practice to depend on something that isn’t a true feature of the behavior. Maybe I’m thinking too strictly.
If there’s a different way, I would suggest it. But this seems to be the best method.
I like the timer over the wait. You can use a system timer or object timer. I used the object bc you can replace the 1 second with an object variable to create individual delays.
Ahhh, this works perfectly, thanks!
I suppose I can see why you were hesitant to do it this way. Although, since the extensions can be freely edited once installed, I’m assuming that using them in a more unorthodox way like this can be seen as an “advanced feature” perhaps?
I tried earlier to recreate the rotation using math like sine and cosine (That’s the green ball you see in the GIF, it was made with math instead of the extension), although, I later figured that since the extension was readily premade, it would be better not to recreate the wheel, so maybe the extensions are intended to be used in such a way like this? Who knows?
I also switched to a timer to shrink down the events like you suggested
Again, I appreciate the assistance
My concern is if the extension was updated it might break your projects. Although, you would have to manually update the extension and recompile it. So, it wouldn’t just one day break it. Still, I prefer a bit of separation. It’s a simple enough extension and the linking seems to be crucial to it. So, I think it should be stable and ok.