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
  • 132k
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
  • 132k
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
  • 118k
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
  • 221
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,000
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,240
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,243
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
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
  • 118k
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
  • 132k
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
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
  • 11.6k
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
  • 118k
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

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
  • 132k
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
1 vote

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
  • 111
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,959
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
Accepted

Libgdx spawning enemies at random time

You can use the delta variable of the render() function. This variable is a float value of the time elapsed since last render ...
Mayuso's user avatar
  • 927
1 vote

Obstacle spawn constraints in Jetpack Joyride

I think you should try the Jetpack Joyride way of doing it using interval and probability spawn. It is a simple implementation and allows you to tweak and test it out quickly. And if it works you may ...
Mattias's user avatar
  • 750
1 vote

Object array in unity not instantiating properly

It looks like you want something like this: ...
DMGregory's user avatar
  • 132k
1 vote
Accepted

How to spawn GameObject exactly in front of another object?

This example might be what you are looking for : ...
Shashimee's user avatar
  • 1,240

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