• 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!

3D [Solved] collision_circle and a set ammount

D

David11

Guest
Hi Members,
Right at the moment, I am doing a horror game simmilar to PT. I have a Tv set, that will do nothing, until you have been standing infront of it, a set number of times. Once you have visited the tv minimum, 3X, it will then play an audio. This audio (my friends are recording it :D ) will play a violent attack between wife VS husband. After the audio ends, he will then take a gun, and blow her brains out, which comes out the tv, and alll over the wall. HAHA I know its vicious.

At the moment, I do not have this audio, nor is the tv ready. For now, I am using a coffee table. When I come near the coffee table 3X, it will disapear. I thought the process was simple. I cant seem to set an instance, a certain number of times. After searching the forums, a numer of times, I did believe this would work:

with (obj_CoffeeTable) {
if (collision_circle( obj_CoffeeTable.x, obj_CoffeeTable.y, 20, obj_Character, false,false )> 3)
then
{
instance_destroy();
}
}

This actually deletes the object on the first try, not the third. Less than or equal to, doesnt do anything. Ive even used the correct procedure with == . Nothing. What am I doing wrong?
 
collision_circle returns an instance id that has been collided with. Not a number you can check.

You need to count the number of times you get within range of the coffee table and then delete the table when that number reaches or exceeds 3. Also, you don't need a collision check for this, a simple distance check will be easier and more efficient by far.

Here is an example. I think it will work, but I can't be for certain. I just suggest you make certain you understand what I'm doing here before copying and pasting.

Create:
Code:
times = 0;
in_range = false;
Step:
Code:
if (point_distance(obj_Character.x, obj_Character.y, obj_CoffeeTable.x, obj_CoffeTable.y) <= 20) //Checking if under a distance of 20 from the coffee table.
 {
 if (in_range == false) //If it has not been in range
  {
  times += 1; //Count up one time that it has been in range
  in_range = true; //State that it is in range
  }
 }
else //It is not in range then
 {
 in_range = false; //It is no longer in range
 }

if (times >= 3) //If has been in range 3 times
 {
 instance_destroy();
 }
 
D

David11

Guest
Nice! Yes I totally I understand your code. Even though, just by looking at it, you would think it 100% would work. But it didnt. Doesnt make sense. So what I added was a counter. I created it, and every time I collided with the coffee tale, it would add one. So after having a collison with it, the counter went up one, but that was it. Never went to two. So I think its a code somewhere else, doing something. Not sure. I'll brb and give an update.

Ok, your update, with the different code, made it work, Thank you. I also changed the number of timesto ten, and this worked after 10 times. Nice work, Thanks again.
 
Last edited by a moderator:
Top