[SOLVED] How to make a random point spawn for a player before the game starts?


#21

Thanks for the suggestion to help with my project, I will think about it and give feedback. I will also mean participation in the development of joint projects. :slightly_smiling_face:


#22

Thanks a lot @MasalovAndreey.


#23

Without a link to the project, it’s a bit difficult to say what exactly the problem is. My guess is that is a first frame issue where the app may be initialising everything in the first frame which takes a little while (or long enough to see the initial position to be).

You can get around this by disabling the camera in the project and then enabling it at run time after the random positioning.


#24

Thank you for the proposed method. In my project, the tilt angles of the weapon and the player’s movement is based on the direction vectors of the camera and camera angles. I turned off the camera and made a check on its state (on or off) in functions where its coordinates or angles are used. After that, I used the setTimeout() function to turn on the camera after working out all the initialization functions. This method works, but only after loading, for a short period of time, a black screen is displayed. I think that can add a second camera and display, for example, a countdown timer before the start of the match, after which you can switch cameras. Thanks again. :slightly_smiling_face:


#25

The link to the video.


#26

The black screen is displayed since there is no active camera. I think your proposed method will work perfectly.


#27

The project link is more useful as it allows people to look over the existing project/fork it to do a proper fix.

At the moment I’m only guessing what the problem is and can give a ‘catch all’ solution.

There’s a postInitialize function that you could use instead of timeout which gets called after all initialize functions


#28

@yaustar, I finally got to this problem and made 2 spawns on this scene. Could you see, what could be the problem? Thanks. :slightly_smiling_face:


#29

I found that the problem with what can be seen as a player moves, occurs in Google Chrome browser. In Mozilla Firefox, everything works correctly. I tried using the postInialize() function, however, it did not work in my case. After launching the scene, I also saw the player moving to a random starting position in the Google Chrome browser. I also tried using the zero delay setTimeout() function. It works, however, a black screen is displayed for a few hundredths of a second, which looks terrible.

I solved the problem with the second scene, which contains the game menu. After loading the scene with the game I check, if the player is in a random position and if so, then I turn on the camera. This works in all browsers.

If you start this scene now, you will see how the player is set to a random position in the Google Chrome browser, since there is no transition between scenes. In Mozilla Firefox browser, everything works correctly.


#30

There’s a browser checker that’s quite easy to use.


#31

Thanks for the link and help, I really appreciate it. :slightly_smiling_face:

I thought about it, that I can check on which browser the game is running and execute the corresponding code. However, I decided that since there is a way to get around the problem through the second scene, it is better to use this method. If you do additional checks, it’s extra code. In addition, I ran the script from your link, and it was false for the Google Chrome browser, since window.chrome.webstore is no longer supported in Google Chrome since version 71.