Im probably the most annoying over here, posting so much .Anyway, im searching all over the internet before coming here, so i wont bother you too much, but some things i cannot find and i dont know how to get them done.So every 1,5 second a random coin from one group is spawned, but some are spawning inside the border, i did some borders myself and destroy every coin that gets in the collision with the border, the problem is that isnt working properly, some coins are spawning at the right time (1.5 sec) and some in 4 seconds or so. Home i made myself clear enough. thx a lot
Maybe it seems to spawn after 4 seconds because all the coins created after 1.5 seconds are colliding with the border and so you need to wait sometime 4+ second to get one that is not colliding.
What I would do is use the RandomInRange(min,max) expressions when creating the objects and simply enter the min,max value that is not including the border to be 100% sure we are not creating coins that is colliding with the border.
Or instead of deleting and creating an other one at random position, get the one that is colliding and move it.
If coin is colliding with the right border, move coin left Random(200) or something.
If coin is colliding with the left border, move coin right Random(200)…etc
This way, you can be sure to get a coin within few frames after 1.5 seconds that is not colliding with the border and don’t need to wait 4 seconds under any circumstances.
I take it 1058 is the width of the scene from 0-1058 and 1800 is the height of the scene from 0-1800
If the border is right at the edge of these values, all you need to do is take the width and height of the border sprite as the minimum value and then also subtract it from the maximum which is the width and height of the scene. Then you also want to take in to account the width and height of the coins at the minimum and maximum value to end up in between the borders without overlapping or colliding with the border.
I really appreciate your help, imma be honest with you, i have no idea how to do what you told me to, but im going to figure it out. I really appreciate you guys
Dude, just put it in actions, using variables (you have to replace “coin” by the actual name of your coin object and “char” by the actual name of your main character, that’s are the only things you have to change):
[code]----------Do this once at the scene start:
Do = floor(ScreenWidth()/2) + coin.Width() to the value of the variable “xLength”
Do = floor(ScreenHeight()/2) + coin.Height() to the value of the variable “yLength”
----------And do this to spawn a coin in a random position inside the current visible section of the scene:
Do = char.X() - xLength to the value of the variable “minX”
Do = char.X() + xLength to the value of the variable “maxX”
Do = char.Y() - yLength to the value of the variable “minY”
Do = char.Y() + yLength to the value of the variable “maxY”
Create object “coin” at position RandomInRange(minX, maxX) ; RandomInRange(minY, maxY)[/code]
Cool, but that will only work if the camera isn’t following the main character.
The camera has nothing to do with this. We are trying to spawn coins in a given area of the scene regardless where the camera or player is at the given moment. If the OP trying to spawn coins around the player then obviously need to take that in to account as well but not otherwise unless I’m missing something.
i have no idea how to do what you told me to
The example I give you was only a dummy text to give you an idea but it would not work as-is.
In my examples the minX, maxX, minY, maxY are scene variables and the values I assign to the variables are expressions to calculate the area between the borders.
If the size and position of border and size of the coins doesn’t change, you need to do this only once at the beginning of the scene.
Then X and Y also scene variables to calculate a random position for the coin that hopefully will not collide with the border.
I assume, you have 5 border objects. One on the Left, on the Right, on the Top and on the Bottom.
Replace LeftBorder, RightBorder in the expressions with the name of your border object.
Then I used Coin as name of the coin object in the expressions, however Coin.Width() and Coin.Height() would work only if you have at least one coin in the scene at the beginning. In case you have a coin in the scene at the beginning, replace Coin with the name of your Coin object and in case you have no coin in the scene at the beginning, replace the entire expression with an actual width and height value of the coin sprite. So instead of Coin.Width() use an actual number.