GMS 2.3+ [SOLVED] Shooting Code and Solid Objects

T2008

Member
My game is a 3/4 zelda/isometric perspective. Currently, solid objects destroy the bullets and create an explosion. The issue is that when shooting, the solid object destroys the bullets at less than ideal places. For example, when shooting from the south, the bullets get destroyed at the base of the object, (eg the bottom of a bush or chair, etc ), instead of waist high/in middle of object. A remedy I have come up with is to create a separate bullet pass through solid object that stops the player (at the base of the object), and then placing a solid object in the middle of the object that stops the bullet, so it looks like the bullet is hitting in the middle/waist high of the object.

The above looks okay so far (not fully tested yet from all directions, etc) but it is a little tedious to implement. Has anyone encountered this issue? Any ideas as to how better to handle this?? Any suggestions would be greatly appreciated!
 
Last edited:

angelwire

Member
Here's an idea you could try, have two bullet sprites, one with a mask for colliding from the top, another with a mask for colliding from the bottom
When you fire a bullet, set the sprite depending on whether it's moving up or down
 
First off I need to know where in the world you are, and what direction your computer monitor is facing to work out where south is.

Secondly, it sounds like you just need to check the height of your bullet against the height of the other object. So just run a check like this:
GML:
if(y > other.y + amount)
 

T2008

Member
Thanks for the response. I probably didn't explain my set up well, but I can't imagine how to implement what you have suggested. The bullet is a small object. Example: a tall back wall or hill stops the player at its base. The bullet should explode in the center of the back wall/hill, which is way higher up than the sprite height of the bullet. So the bullet has to travel quite a distance to make it to the center of the wall. If the objects were smaller this might work. An issue with this might also be that the objects are wide variety of sizes and not standard so I'm not sure if having one sprite per direction would work.

Good idea though. Maybe with a lot of experimenting it might work.???
 

angelwire

Member
Do you want the bullet to always hit the center of the wall depending on how big it is, or always hit waist high?
If you always want it to hit waist high you could set up the masks like this, where the collision mask for the bullet up sprite is where the player's feet would be if the bullet is at the player's waist.
example.png
 

T2008

Member
Waist high. I see what you are saying now. I will try your suggestion. It does seem like a relatively simple solution. Thank you so much for responding.
 

T2008

Member
I started trying both of your suggestions and using PhallicSpleen's idea, I seem to come up with a simple solution that looks decent so far.
Angelwire, I think your idea could work as well. Thanks so much to both of you. I've posted the code below in case anyone is interested. I added the 20 increment to make it look waist high (the explosion offset has to do with the various types of guns and bullets). I'm continuing to test, but I think this looks good so far.

COLLISION EVENT WITH SOLID OBJECTS
Code:
if (y > other.y) && (xprevious = x) {
    instance_create_depth(x+explosion_offset_x,y+ explosion_offset_y+20,0,explosion_object);
}
if (y <= other.y) && (xprevious = x) {
    instance_create_depth(x+explosion_offset_x,y+ explosion_offset_y-20,0,explosion_object);
}
if (xprevious != x) {
    instance_create_depth(x+explosion_offset_x,y+ explosion_offset_y,0,explosion_object);   
}

instance_destroy();
Edit: I edited the above to include code to prevent explosion moving up/down when bullet is travelling left/right.
 
Last edited:
You're suposed to use the && without closing and reopening the brackets like this:
GML:
if (y > other.y && xprevious = x)
Edit:
For what it's worth I think there is a more aesthetic way to write your code. Instead of using two if's, use an if and an else and you will be able to tell at a glance how exactly the two sections of code relate. Also instead of asking the same question twice just ask it once, and put brackets around everything that is dependent on the answer.
GML:
if (xprevious = x) {//No need to ask the same question twice, just put it all in nested brackets
    if (y > other.y) {
        instance_create_depth(x+explosion_offset_x,y+ explosion_offset_y+20,0,explosion_object);
    }
    else //y <= other.y does the same thing, but at a glance, it's easier to understand whats logically happening
    {
        instance_create_depth(x+explosion_offset_x,y+ explosion_offset_y-20,0,explosion_object);
    }
}
else//again xprevious != x does the same thing, but this is more understandable
{
    instance_create_depth(x+explosion_offset_x,y+ explosion_offset_y,0,explosion_object); 
}
 
Last edited:
Top