SOLVED In the platform game, the bullets did not touch the boxes.

lock46

Member
In the game on the platform, I made a box and if this box is formed, a wall is formed inside the box and holding the player, but the bullet I hit with the gun does not touch the box. I will be glad if you help
tarantula.png
"Crate" collision mask;
monomer.png
"Clip(wall)" collision mask;
jaklemun.png
"Bullet" collision mask;
Ekran Alınsdadatısı.PNG
"Crate" Create event;
GML:
hp = 10;

mywall = instance_create_layer(x,y,"clip",Obj_clip)
with (mywall)
{
    image_xscale = other.sprite_width / sprite_width;
    image_yscale = other.sprite_height / sprite_height;
}
"Crate" Destroy event;
GML:
with (mywall) instance_destroy();
"Crate" Step event;
GML:
if (hp <= 0){
    instance_destroy();
}
"Crate" collision "Bullet";
GML:
instance_destroy();
"Bullet" collision "Crate";
GML:
instance_destroy();
"Bullet" collision "Clip"(wall);
Code:
instance_destroy();
 
Last edited:

Gamebot

Member
In the game on the platform, I made a box and if this box is formed, a wall is formed inside the box and holding the player, but the bullet I hit with the gun does not touch the box. I will be glad if you help
I am a bit confused...

Are you wanting the bullet to hit the box and it isn't?
I don't see code for the bullet to fire from the gun. Is that what you are wanting to know how to do?
 

lock46

Member
I am a bit confused...

Are you wanting the bullet to hit the box and it isn't?
I don't see code for the bullet to fire from the gun. Is that what you are wanting to know how to do?
the error here is that the bullet fired from the gun does not touch the box
if the bullet collided with the box, the box would be destroyed but it doesn't disappear I have no idea where there is a problem


I wrote a code like this;
"if the box collides with the bullet the box will be destroyed"
 

lock46

Member
If a box is placed in the room, an invisible clip (wall) is created that holds the player the same size as the box, because the player hits the box and stops, the bullet does not touch the box, the bullet must touch the box for the box to disappear
I want the bullet to touch the box because the box has to disappear it is the obstacle holding a player

my english is a little low
 

Pixel-Team

Master of Pixel-Fu
Your collision shape should extend beyond the tail of the bullet. Presumably anything the tail hits would have been hit by the front. This will be to ensure that the bullet does not travel faster than its collision box can collide. You can improve this by making the actual bullet graphic start on the right of the sprite, changing the center of the sprite to be the center of the bullet graphic, and this would allow you to extend that collision shape almost three times the length of the actual bullet.
 

lock46

Member
Your collision shape should extend beyond the tail of the bullet. Presumably anything the tail hits would have been hit by the front. This will be to ensure that the bullet does not travel faster than its collision box can collide. You can improve this by making the actual bullet graphic start on the right of the sprite, changing the center of the sprite to be the center of the bullet graphic, and this would allow you to extend that collision shape almost three times the length of the actual bullet.

I tried to understand a bit with my poor english and changed the collision mask of the bullet, so what options should I do?
1
pro1.PNG
2
pro2.png
3
pro3.png
4
pro4.png
5
pro5.png

I will continue
 

lock46

Member
there is also an error that the direction of the bullet does not change at all because the player shoots from the right and left.
Adsız.png
 

Pixel-Team

Master of Pixel-Fu
#4 looks the best. When you shoot from right to left, the sprite should get flipped, and the collision shape will get flipped with it.
 

TheouAegis

Member
You need to post the code that creates the bullet when the player shoots.

Also, why are you creating Obj_clip on top of the Crate? Why not just use the crates own sprite mask? Your code says if it collides with a crate, destroy the crate, so why even use Obj_clip there? Furthermore, if the bullet collides with Obj_clip, it just destroys the bullet. You don't have code telling Obj_clip to destroy the object it is tied to, so the crate can't be destroyed.

On GMS 2.2 and older versions of Studio, this is A simple fix of just moving Obj_clip to the very bottom of the asset tree. In 2.3, I don't know if there is a simple fix without rewriting your code logic.
 
Last edited:

lock46

Member
You need to post the code that creates the bullet when the player shoots.

Also, why are you creating Obj_clip on top of the Crate? Why not just use the crates own sprite mask? Your code says if it collides with a crate, destroy the crate, so why even use Obj_clip there? Furthermore, if the bullet collides with Obj_clip, it just destroys the bullet. You don't have code telling Obj_clip to destroy the object it is tied to, so the crate can't be destroyed.

On GMS 2.2 and older versions of Studio, this is A simple fix of just moving Obj_clip to the very bottom of the asset tree. In 2.3, I don't know if there is a simple fix without rewriting your code logic.
The reason I created an Obj_clip(wall) inside the chests I want the player or any object to keep bumping into it, I expanded the collision mask of Obj_Crate It's more than Obj_clip but still the Chest didn't disappear, I don't know where is the problem, The reason I built the chests is I want it to block the players and objects The player shoot the chest It should break it and continue on its way, I will share the code of the bullet, wait...
 

lock46

Member
"Öbj_m4"

Weapon create code and firing code
Create event;
GML:
can_fire = true;
firing_delay = 10;
Step event;
GML:
//Shoot
if can_fire and mouse_check_button(mb_left)
{
   audio_play_sound(Sound_m4,5,false);
   var bullet = instance_create_layer(x, y,"Instances_bullet", Obj_bullet) ;
   bullet.direction = point_direction(0, 0, image_xscale, 0) ;
   alarm[0] = firing_delay;
}
Begin step event;
GML:
image_xscale = Obj_player.image_xscale

x = Obj_player.x+30
y = Obj_player.y+3.5
if Obj_player.image_xscale = -1
{
  x = Obj_player.x-30
}
Alarm[0];
GML:
can_fire = true;
 
Last edited:

TailBit

Member
The bullet move so fast that it skips the collission box? Could that be it? if so then you need collision_line .. check between x,y and xprevious,yprevious
 

lock46

Member
The bullet move so fast that it skips the collission box? Could that be it? if so then you need collision_line .. check between x,y and xprevious,yprevious
I tried, the bullet sometimes hit the box, sometimes it didn't, it touches occasionally while running and shooting, it touches a little when approaching the box, it's a very bad situation.
 

lock46

Member
I think this problem is caused by Obj_clip(wall), when I delete the Obj_clip(wall) creation code, the bullet touches it, but when it does it doesn't. Is there any other solution to keep the player so I want Obj_crate to be solid so that it stops the player
 

lock46

Member
Let's try a solution for the last time... When I shoot the bullet from the right, the same direction when I shoot from the left, the same direction, how can we change it, there is a firing code at the top
 

woods

Member
crate creates the clip.. so clip is drawn on top of the crate.
bullet has collision with both crate and clip = destroy the bullet...

the bullet is checking the clip collision before the crate collision?
since bullet gets destroyed from the collision with clip, the crate check doesn't happen?





i am in agreement with TheouAegis
Also, why are you creating Obj_clip on top of the Crate? Why not just use the crates own sprite mask? Your code says if it collides with a crate, destroy the crate, so why even use Obj_clip there? Furthermore, if the bullet collides with Obj_clip, it just destroys the bullet. You don't have code telling Obj_clip to destroy the object it is tied to, so the crate can't be destroyed.
i would drop the clip altogether and just use the crate ;o)
 

woods

Member
I want the player to stop when the player collides with the crate..
couldnt you simply move the code from the clip to the crate, and eliminate the check for the clip that destroys the bullet?

edit:
eliminate the check for the clip that destroys the bullet while inside the crate?
 

lock46

Member
crate creates the clip.. so clip is drawn on top of the crate.
bullet has collision with both crate and clip = destroy the bullet...

the bullet is checking the clip collision before the crate collision?
since bullet gets destroyed from the collision with clip, the crate check doesn't happen?





i am in agreement with TheouAegis


i would drop the clip altogether and just use the crate ;o)
The reason I put a Clip is because I want the player to stop when the player collides with the crate, the crate has to be an obstacle, the Clip is an invisible block holding the player. If I remove the case that the bullet disappears when it collides with it, the bullet goes through the ground, goes through everywhere, it's not nice
View attachment 40639
 

lock46

Member
No, I can't do such a thing, if I remove the clip and replace it with the box, the new block holding the player will be the box, I'll put my box everywhere this is ridiculous
index.png
 

lock46

Member
When I don't put Obj_clip in the box, the problem is solved, but the box does not stop the player, it does not become a solid
 

lock46

Member
Obj_bulllet collision Obj_clip "instance_destroy" I can't remove it, if I remove it the bullet will start to pass through the wall
benil.png
 

woods

Member
if the crate destroys the clip attached to it when it gets destroyed, just have the bullet destroy the crate... i think you are trying to over-complicate your logic.. by having everything check if they are colliding with everything else and destroying things..



these two right here should be all you need to destroy the crate, the clip, and the bullet

"Bullet" collision with "Crate"
instance_destroy(other); //bullet destroys the crate
instance_destroy(); //bullet destroys itself


"Crate" Destroy event
with (mywall) instance_destroy(); //crate destroys the clip when its destroyed

there is no need to check the bullet and the clip ;o)
 

lock46

Member
if the crate destroys the clip attached to it when it gets destroyed, just have the bullet destroy the crate... i think you are trying to over-complicate your logic.. by having everything check if they are colliding with everything else and destroying things..



these two right here should be all you need to destroy the crate, the clip, and the bullet

"Bullet" collision with "Crate"
instance_destroy(other); //bullet destroys the crate
instance_destroy(); //bullet destroys itself


"Crate" Destroy event
with (mywall) instance_destroy(); //crate destroys the clip when its destroyed

there is no need to check the bullet and the clip ;o)
Obj_bulllet collision Obj_clip "instance_destroy" I can't remove it, if I remove it the bullet will start to pass through the wall
View attachment 40641
 

lock46

Member
No solution for a few days, it's very frustrating, if the problem is not resolved I will remove the boxes from the game :(
 

TheouAegis

Member
There appear to be multiple issues, and fixing one isn't going to fix the mall. So first question, what is in your bullet create event? I see that when the player shoots the bullet, you are sitting the bullets direction, but what is setting the bullet speed?

Your bullet step event is empty, correct? You do not have any code that says "x +=" or :
"x = x +" in it, correct?

Second, only one object will run its code at a time. It doesn't matter if you have a collision code in the bullet or Collision code in the crate. If you destroy the only one of the instances in the Collision code, then the other ones will not be able to run his code next. So if the bullet runs code first, it's going to destroy itself, and then the crate won't be able to detect a bullet because the bullet was already destroyed. Conversely, if the crate gets a check first, it will destroy itself, and then the bullet won't know it collided with a crate. Whoever has the Collision check needs to destroy both itself and the other object.
 

lock46

Member
There appear to be multiple issues, and fixing one isn't going to fix the mall. So first question, what is in your bullet create event? I see that when the player shoots the bullet, you are sitting the bullets direction, but what is setting the bullet speed?

Your bullet step event is empty, correct? You do not have any code that says "x +=" or :
"x = x +" in it, correct?

Second, only one object will run its code at a time. It doesn't matter if you have a collision code in the bullet or Collision code in the crate. If you destroy the only one of the instances in the Collision code, then the other ones will not be able to run his code next. So if the bullet runs code first, it's going to destroy itself, and then the crate won't be able to detect a bullet because the bullet was already destroyed. Conversely, if the crate gets a check first, it will destroy itself, and then the bullet won't know it collided with a crate. Whoever has the Collision check needs to destroy both itself and the other object.
I deleted all the collisions related to "obj_bullet" and did something like
"Obj_bullet"Step event
GML:
if place_meeting(x,y,Obj_crate)
{
    instance_destroy()
}
if place_meeting(x,y,Obj_clip)
{
    instance_destroy()
}
"Obj_Crate"collision"Obj_bullet"(crate hp = 10)
GML:
hp -= 3
And problem solved!,

you've been an inspiration to me, you help me with all my problems thank you, also thank you to everyone else who helped
 
Top