Skip to main content
8 votes
Accepted

Set a 'chance to spawn' for each GameObject in an array

Here's one way to do it, using a custom struct to store object-weight pairs: ...
DMGregory's user avatar
  • 135k
5 votes

How to synchronize the speed of spawned object and spawning time interval?

This is a simple application of the distance-velocity-time triangle: (Image via BBC "Bitesize Maths") float timeBetweenSpawns = spaceBetweenBalls/ballSpeed; ...
DMGregory's user avatar
  • 135k
5 votes

how do i NOT let this object spawn at a certain area?

A simple solution which covers a wide variety of circumstances which could invalidate spawn locations can be to simply check if the randomly generated position is within a "forbidden zone" ...
Philipp's user avatar
  • 120k
4 votes

How to make sure that the set of randomly spawning obstacles is passable?

If the blob has a constant vertical speed, and you know the horizontal speed of the incomming objects, you can use those variables to calculate the minimum and maximum angles the blob can travel to at ...
sjoerd216's user avatar
  • 219
4 votes
Accepted

Spawn rates and variable time steps

I'd go with something like this (pseudo-code): ...
Vaillancourt's user avatar
  • 16.3k
4 votes
Accepted

How to implement arcade-style spawning?

Don't trigger based on the camera's position. Trigger based on the player's. Once the player enters the trigger you spawn the enemies just outside the edges of the camera's view. Since the camera ...
Casey's user avatar
  • 2,045
4 votes
Accepted

Godot: Spawn an object in 3D

Spawning nodes dynamically works the same, whether it's 2D or 3D, and you kind of were on the correct track: Load the scene as a template. Instantiate said scene template as a new node. Add the new ...
Mario's user avatar
  • 8,497
3 votes
Accepted

Instantiate object with spawn time?

I would suggest creating a coroutine which takes three arguments, one for the gameobject which is to be instantiated, another for the number of times it should be instantiated, and the final parameter ...
jnelsis's user avatar
  • 61
3 votes

How to spawn multiple objects in the same frame?

You could use a for loop and a random integer between 1 and 4. ...
Shashimee's user avatar
  • 1,260
3 votes
Accepted

Spawn a prefab at random y position with different gap between prefabs

In your update, you describe placing the walls on either side of a room. From your description and diagram, you intend to use random heights for the walls. Instead, I would recommend randomly deciding ...
Gnemlock's user avatar
  • 5,273
3 votes
Accepted

Ensure that random enemies don't spawn just near the player

The simplest system I can think of consists in testing the position of the new enemy before your screen.blit(), like so: ...
Sisyphe's user avatar
  • 66
3 votes

Godot: Spawn an object in 3D

This is your PackedScene: const FlareScene := preload("res://flare.tscn") You instance it like this: ...
Theraot's user avatar
  • 27.2k
2 votes

Unity2D: How to destroy spawned object once it exit out of camera's view?

OnBecameVisible and its counterpart has a few gotchas. It works only if the gameobject has geometry. The editor view also triggers these events. You might want to ...
volvis's user avatar
  • 271
2 votes
Accepted

How do open world games handle efficiently enemy respawn?

When you need to persist the state of a chunk but you are running out of memory, consider persisting it to the hard drive. If your game has enough complexity and data to warrant it, you might want to ...
Philipp's user avatar
  • 120k
2 votes
Accepted

How do I respawn a prefab that matches the name of the game object I just destroyed?

Edit: whoops! I had the idea that I wanted the prefab of the object itself to remember which prefab it's spawning from, but neglected a wrinkle of prefab spawning: when you spawn a copy of an object, ...
DMGregory's user avatar
  • 135k
2 votes

How do I respawn a prefab that matches the name of the game object I just destroyed?

First, you should combine this information: ...
Draco18s no longer trusts SE's user avatar
2 votes

Unity: Player Gets Stuck Between Tiles

In many situations, depending on how collision works in your game, you can use the Sphere Colliders or Capsule Colliders instead of the box Colliders. This will let the character slider over Box ...
Goose's user avatar
  • 121
2 votes
Accepted

How can I spawn items based on probabilities?

There are different ways of doing this. Here I am giving two ways of getting a weighted game object. The first one is easy but not a good practice and has a lot of issues. I have commented on the code ...
Shuvro Sarkar's user avatar
2 votes

How can I spawn items based on probabilities?

In genetic programming, this is called the roulette selection function/algorithm. Here's one way to implement it: ...
Pikalek's user avatar
  • 12.4k
2 votes
Accepted

Spawn Array of GameObjects to Array of Transforms

Would simple for loop work? ...
sorko's user avatar
  • 61
2 votes
Accepted

Random Spawning Traffic at Pace Fitting "Frogger"-style Gameplay

First of all, I see a big problem with your code. You are potentially spawining a car each Update. That means you are making the spawn frequency dependent on the ...
Philipp's user avatar
  • 120k
1 vote

My GameObject keeps spawning when it shouldn't

What happens: Your object state is (x = -10, floorsSpawned = 1) You object moves to the limit of the first if (state: x = -18.1, floorsSpawned = 1) and the first object is instantiated (floorsSpawned ...
monty's user avatar
  • 384
1 vote
Accepted

How can a variable have two values at the same time?

Begin play called before you are setting the variable. On dynamically spawned actors begin play will be called instantly before any other bp node will be executed.
Coldsteel48's user avatar
1 vote
Accepted

Actor does not perform action when spawned?

Go to the NPC blueprint at the top of the screen, click Class Defaults, search for the Auto Possess AI option on the Pawn menu and select the Placed in World or Spawned option. Image to facilitate: ...
Boneco Sinforoso's user avatar
1 vote
Accepted

How to Destroy an Instance of a Prefab Without Removing the Prefab?

Your SpawnObstacles script is referencing a gameObject in the scene, rather than an actual prefab. To create a prefab, drag and drop your Obstacles object to your assets folder. Then make sure that ...
Sean Carey's user avatar
1 vote
Accepted

Rotate object to closest clone?

I notice your script looks for enemies only inside a distance of 20 units. So we don't need to scan the whole scene for enemies using FindGameObjectWithTag, we can ...
DMGregory's user avatar
  • 135k
1 vote

Make enemy disappear after spawn

You can call Destroy with a 2nd parameter indicating the delay before the destroy occurs : ...
Hellium's user avatar
  • 2,949
1 vote

Display image a couple seconds after an enemy spawns?

Well, all those co-routines and waiting for some seconds are nice but, why not just use Invoke() for this purpose as well? ...
John Hamilton's user avatar
1 vote

Game maker studio 2 Random spawn locations are not random

I am almost certain that this is a setting for debugging purposes. Debugging randomness is a pain so sometimes engines do a pseudo randomness with some sort of seed so that you can have consistency ...
Jonathan Camarena's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible