Quest: Mining Quest
Challenge: Run Away
Feel free to share your solutions, ideas and creations below. If you get stuck, you can find some ideas here for completing this challenge.
Quest: Mining Quest
Challenge: Run Away
Feel free to share your solutions, ideas and creations below. If you get stuck, you can find some ideas here for completing this challenge.
At first, I was worried, that I need to remove rocks (if there are any) in the desired spot. But the exit works as intended layered on top, so no problem there.
I already put in variables for the size, so I used those and multiplied with 0 or 1 randomly for x and y.
private void SpawnExit()
{
int xExit = Random.Range(0, 2) * (xSize - 1);
int yExit = Random.Range(0, 2) * (ySize - 1);
GameObject newExit = Instantiate(exitPrefab, new Vector2(xExit, yExit), Quaternion.identity);
}
Nice way of finding random corners
Oh I like how clean this is. I ended up making an array with four Vector3 for the different corners but of course that used a lot of ‘magic numbers’ that we’re supposed to avoid.
I agree, this is such a nice solution! I threw the four corners into a vector2 array and then randomly chose one of those to place the exit, but this would become a problem when the layout of the mine would change later.
Took me too long to understand why your solution works because I thought “What happens when the random number is 2 and that is multiplied by say 19?”, but the random number will never be 2 because it’s NOT maximally inclusive in Random.Range. I had to read up on it. Floats are maximally inclusive, Ints are maximally exclusive. Cool!
Always fun to get a “two years” later response. I’m glad that you like the solution. Different range functions being inclusive or not are always tricky, depending on type and language.
This quest was very difficult for me and I had to study the solutions for each challenge. While I’m a bit disappointed that I couldn’t accomplish it on my own, I’m glad I was able to learn primarily from your solutions on this one. Taught me a bunch so thanks again