How would i randomly spawn enemies two enemies to replace some cubes and only spawn two more if i kill those two?For the python code of the last blend in this link.https://blenderartists.org/forum/showthread.php?411416-I-could-not-figure-out-how-to-dig-on-any-ground-i-walk-on
it would be to your great benefit to be fluent in python. until then, complex things are not a good idea. start small, and then keep adding on. instead of randomly spawning 2 enemies, spawn one at a specific location. once you figure out how to spawn enemies at specific locations, add a randomize function.
what your asking for is complex game mechanics, which will only be of benefit if they are optimized for your game setup. might as well ask someone to make you the better half of a game for you. then the issue of not being executed like you imagined comes up, requiring further effort to refine. effort which few are willing to put forth.
ill be happy to help with understanding python, but im not going to make you a game.
LostScience, you’re asking a lot of questions about your project that you could answer yourself if you learn to program in Python.
These questions are all specific cases of generic problems, and learning those generic solutions will give you the solutions to more particular problems. Furthermore you develop a mindset to approach problems that means you can usually think of a solution without having seen the problem before.
For example, for this problem there are several components:
-
How to spawn replacement.
-
When to spawn replacement
-
How? AddObject is your friend. To unify this with how the enemies are spawned in the first place, use the same code you use to add enemies.
-
Events - If you are going to use logic bricks, have the sensor that triggers the endObject on the enemy also trigger a Python controller that runs some “on death” code.
No need to use Python at all. Just think about what you want to do:
A) spawn enemy
B) spawn two enemies
C) spawn enemy at random location
-> when you can spawn one enemy you can do it again. So B) should not be a big deal, as long as they do not depend on each other.
Spaw object
Spawning an enemy is simply “add object” either via actuator or via python. Both solution have the same value.
Location
Spawning at a specific location: place the reference object at the desired location beforehand!.
The order is: first place reference object, then add object.
How to place the reference object? By setting a position. Yes, it is as easy as it sounds.
Random placement
How to make it random? -> play an action on the reference object. Choose a random key (random actuator feeds action actuator in property mode)
The order is:
- create random value for property
- play action via property
- add object
Example: when the property value gets random value 3, the animation plays the pose of frame 3. Ensure the poses of discrete frames (whole numbers) are valid spawn points. (Additionally the animation can contain orientation frames).
Multiple objects
How to add two objects?
Have two reference objects, or do it one after the other.
Here you can benefit from Python, when you want to add several enemies at the same time as Python allows loop.
Potential problems
Skipping occupied locations.
There are two solutions:
A) before adding check the location, if available then add if occupied, start again.
The problem with that method is, that with less available locations the likelihood to find a valid location will decrease dramatically. You will not even know when it is impossible to find a valid location.
B) ensure to choose unique locations (within one throw).
(Please note: this does not check if the location is occupied, I simply assume when choosing two different locations they can’t be occupied as they are different)
Pretty easy: do not directly chose a random location (frame in animation), you chose a random offset. You can start with a constant value (e.g. 0), then you add the random value (e.g. 5) you get as first position 0+5 = 5. You do that again with the next spawn. E.g. you get random 3 so you calculate 5+3=8. So the first enemy will spawn at location 5, the second at location 8. As long as you ensure the random value is >0 you should always get a unique number.
I hope you get the idea.
I think i will use the logic bricks to do it.Instead of python.It is easier.I did think of something.