• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Rocks spawn on each other

T

tiberionx

Guest
Hello

So im doing the space rocks tutorial , and instead of making the rocks go through each other I made the object solid and bounce off each other

now when i do the random spawn thing they sometimes spawn on top of other rocks and just stays there.

I used the place_free command, it kinda works i think but im not sure haha
GML:
if(choose(0,1) == 0){
    //sides
    var xx = choose(0, room_width);
    var yy = irandom_range(0, room_height);
} else {
    var xx = irandom_range(0, room_width);
    var yy = choose(0, room_height);
}

place_free(xx,yy){
instance_create_layer(xx,yy, "Instances", obj_rocks);
}
 

FrostyCat

Redemption Seeker
It doesn't work because you missed the if. You can't assume that it will be filled in for you.
GML:
if (place_free(xx, yy)) {
    instance_create_layer(xx, yy, "Instances", obj_rocks);
}
Also, don't bump up topics from 4 years ago, and don't post on the Tutorials section for help on tutorials. Use the Programming section if you have a coding problem.
 
T

tiberionx

Guest
look man, im posting here in the tutorial since i actually have no idea what im doing and i just finsihed the first tutorial, i thought this would be the appropriate section since its part of the tutorial.

did i bump any topic? i started a new thread right?
It doesn't work because you missed the if. You can't assume that it will be filled in for you.
GML:
if (place_free(xx, yy)) {
    instance_create_layer(xx, yy, "Instances", obj_rocks);
}
Also, don't bump up topics from 4 years ago, and don't post on the Tutorials section for help on tutorials. Use the Programming section if you have a coding problem.
im also a complete beginner at coding hence i have no idea what you're talking about
 

FrostyCat

Redemption Seeker
did i bump any topic? i started a new thread right?
You bumped up a 4-year-old topic here for the exact same question.
im also a complete beginner at coding hence i have no idea what you're talking about
I mean replacing this part of your code:
GML:
place_free(xx,yy){
instance_create_layer(xx,yy, "Instances", obj_rocks);
}
With this:
GML:
if (place_free(xx, yy)) {
    instance_create_layer(xx, yy, "Instances", obj_rocks);
}
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
did i bump any topic? i started a new thread right?
You did and you also posted in tutorials. A moderator resolved both things however by removing the necro bump and moving this topic! :) BUT, it's no big deal and don't worry about it. Just please try to post questions in the appropriate forums and in general, dont post in topics that haven't had a reply in over 3 or 4 months. We'd prefer you to make new topics for your own issues than "hijack" someone elses as it makes issues easier to track in general.

But like I say, not a big deal and all resolved!
 
Top