What are some efficient ways to generate random enemy encounters on particular maps?
Right now, I have one huge trigger box covering the floor of a default map (since I’m just experimenting for now). I have placed a collision box around each foot on the player character and I have the following blueprint (though it doesn’t work unless the box is outside of the player’s spawn point).
Given this, what is the best way to set up a random enemy encounter blueprint based on the number of steps taken within some range on a map? That is, how do I have the program factor in the number of steps to determine when a random encounter occurs?
The way I’d do it would be on each step, increment an integer, let’s say “StepsSinceLastEncounter”.
Then do a boolean to check if greater than, let’s say 10, to give it a floor.
If that was True, Divide some number (lower means higher % chance to trigger) by steps taken.
Then, you’ll do “GetRandomFloat” and set the values between 1 and 100.
Compare your first number with that random float.
If the float is LESSER THAN the first number, Set “StepsSinceLastEncounter” and Trigger encounter! This way you’ll get to start again at 0 steps after the fight.
I suppose you’d do either.
If you keep the base functionality on the game mode, and bounce the activity from the Level to the Game mode, you could pass along values such as encounter rate (that’s the number you’d divide by your steps) to be different based on the level, but not have to re-code the entire thing for different levels. I wouldn’t put it on the Character, no, this is more of a GameMode type thing.
Make a function to run on each step on the Game Mode, give it a variable of steps taken, ++ it on each run of the function, input of a Float for the Encounter rate (this will be a variable on your level blueprint) and an output of a boolean (this is your “Trigger encounter? T/F”).
Then, on each collision of the feet like you were talking about, on the collision logic in your level blueprint do GetGameMode-> F_RandomEncounterCounter(or whatever you name it). Then face the encounter trigger however you’re wanting to do that!