Skip to main content
Made the question a bit clearer.
Source Link
Vaillancourt
  • 16.4k
  • 17
  • 55
  • 61

How to properlycan I spawn items based on probabilities?

I'm working on a game where I want to choose which object to spawn based on probabilities. MeaningAssuming the decision to spawn the object has been done by some other process, I'd like the object with the highest probability shouldto have a higher chance of being spawnspawned. An object with 50% spawn probability should spawn more often than an object with 15% spawn probability. I also need to account for instance where a game object has the same spawn probability

GameObject 1 .50 GameObject 2 .25 GameObject 3 .25

GameObject 1 .50 
GameObject 2 .25
GameObject 3 .25 

What's the best way toHow can I implement this logic?

How to properly spawn items based on probabilities?

I'm working on a game where I want to choose which object to spawn based on probabilities. Meaning the object with the highest probability should have a higher chance of being spawn. An object with 50% spawn probability should spawn more often than an object with 15% spawn probability. I also need to account for instance where a game object has the same spawn probability

GameObject 1 .50 GameObject 2 .25 GameObject 3 .25

What's the best way to implement this logic?

How can I spawn items based on probabilities?

I'm working on a game where I want to choose which object to spawn based on probabilities. Assuming the decision to spawn the object has been done by some other process, I'd like the object with the highest probability to have a higher chance of being spawned. An object with 50% spawn probability should spawn more often than an object with 15% spawn probability. I also need to account for instance where a game object has the same spawn probability

GameObject 1 .50 
GameObject 2 .25
GameObject 3 .25 

How can I implement this logic?

edited tags
Link
Jay
  • 23
  • 1
  • 5
deleted 345 characters in body
Source Link
Jay
  • 23
  • 1
  • 5

I'm working on a game where I want to choose which object to spawn game objects based on probabilities. The issue is determining whichMeaning the object to spawn if two objects havewith the samehighest probability should have a higher chance of being spawn.

For instance:

GameObject 1
  probability .02

GameObject 2 
  Probability .03

GameObject 3
  Probability .02

An object with 50% spawn probability should spawn more often than an object with 15% spawn probability. I believe the initial way to do it is,also need to sum up all the probabilities and getaccount for instance where a random number to compare againstgame object has the objects probabilities.same spawn probability

0.03 + 0.02 + 0.02 = 0.07

randNum = rand(0, 0.07)

so ifGameObject 1 randNum < .02 how to determine which object should be spawn?.50 GameObject 2 .25 GameObject 3 .25

Is thisWhat's the correct approachbest way to implement this logic?

I'm working on a game where I want to spawn game objects based on probabilities. The issue is determining which object to spawn if two objects have the same probability.

For instance:

GameObject 1
  probability .02

GameObject 2 
  Probability .03

GameObject 3
  Probability .02

I believe the initial way to do it is, to sum up all the probabilities and get a random number to compare against the objects probabilities.

0.03 + 0.02 + 0.02 = 0.07

randNum = rand(0, 0.07)

so if randNum < .02 how to determine which object should be spawn?

Is this the correct approach?

I'm working on a game where I want to choose which object to spawn based on probabilities. Meaning the object with the highest probability should have a higher chance of being spawn. An object with 50% spawn probability should spawn more often than an object with 15% spawn probability. I also need to account for instance where a game object has the same spawn probability

GameObject 1 .50 GameObject 2 .25 GameObject 3 .25

What's the best way to implement this logic?

Formatting.
Source Link
Vaillancourt
  • 16.4k
  • 17
  • 55
  • 61
Loading
Source Link
Jay
  • 23
  • 1
  • 5
Loading