Page 1 of 1

How to spawn random objects at the top of the screen ?

PostPosted: Wed 9 Jan 2019, 01:50
by JuanIgnacioG
Hello.
First: Sorry for my english, im not a english native speaker
Second: iam a newbie
Iam making a game where i climb rocks that fall down from the sky, and going higher makes you earn more points. My question is: How can i make rocks spawn meanwhile iam going higher? because i already set to create objects in random position, but they just keep spawning at the same place.
Thank you for your time

Re: How to spawn random objects at the top of the screen ?

PostPosted: Wed 9 Jan 2019, 14:05
by Lizard-13
Add an offset in function of the player position or camera top position, if right now for the spawning Y position you've something like:
Code: Select allRandom(10) - 10

or
Code: Select all-50


Use:
Code: Select allPlayer.Y() + Random(10) - 10

or
Code: Select allCameraY() - CameraHeight()/2 -50

Re: How to spawn random objects at the top of the screen ?

PostPosted: Wed 9 Jan 2019, 15:20
by JuanIgnacioG
Lizard-13 wrote:Add an offset in function of the player position or camera top position, if right now for the spawning Y position you've something like:
Code: Select allRandom(10) - 10

or
Code: Select all-50


Use:
Code: Select allPlayer.Y() + Random(10) - 10

or
Code: Select allCameraY() - CameraHeight()/2 -50



Thank you for answering. I changed the Y position, but they keep appearing at the same height.

This is what i made:
The timer "RockCreation" is greater than 1.5 seconds. Action: Create object Rock at position Random(800); Player.Y() + Random(10) - 10.
Reset The timer "RockCreation"

Iam not sure if this is what you were talking about. Good luck with studies.

Re: How to spawn random objects at the top of the screen ?

PostPosted: Wed 9 Jan 2019, 16:06
by Lizard-13
The event logic is right, don't worry. The problem is that you're creating the rocks under the player position, try to create them at
Code: Select allPlayer.Y() - 600

If the player is at the bottom of the screen and the screen size is 800x600,the rocks will be created above the screen, you can create them even a bit upward, to make sure the user don't see the rocks being created:
Code: Select allPlayer.Y() - 650


If it doesn't work I'll need an event screenshot and maybe a screenshot showing the problem in-game or a more detailed explanation of the problem :)