Question about collision and events

Hey guys,

I'm trying to pick up a collision in my game. I have a castle (DraculasCastleObject) and a walking brain (SimpleBrain). The brain is supposed to collide with the castle and damage the castle.

So here is the code for the collision event:

GML:
    global.castle_hp -= 200
    show_debug_message("Drac Simple")
I'm not quite sure what I'm doing wrong. The debug message doesn't show up so I know its not executing that global line.
 

Nidoking

Member
Which object is the collision event defined in? Which collision event is it? How did you define the bounding boxes for the sprites for both objects? Are you using the default Draw event, or have you defined it in some other way?
 
Personally, I wouldn't have an objects HP as a global variable. You can still access that object's variables with objectName.variableName.

And as asked above, are you using place_meeting() correctly? Example in brain object:
GML:
if (place_meeting(x, y, obj_Castle))
{
    obj_Castle.HP -= 200;
    show_debug_message("Drac Simple");
}
 

Evanski

Raccoon Lord
Forum Staff
Moderator
my guess is you have multiple walking brains all using the same global so it seems like nothing is happening because all the objects are arguing over what the global hp actually is
 
Which object is the collision event defined in? Which collision event is it? How did you define the bounding boxes for the sprites for both objects? Are you using the default Draw event, or have you defined it in some other way?
The object (I wrote SimpleBrain above and made a mistake. I meant BigBrainObject.

The BigBrainObject is in the collision event of the object DraculaCastleObject.

The bounding boxes for the castle is: Fulll Image and Precise for Frame.

The bounding boxes for the BigBrainObject is: Automatic with Rectangle.

No. The objects are created in the room, spawned by a controller. I'm not using GML to detect the collision, I'm using the built in event.


my guess is you have multiple walking brains all using the same global so it seems like nothing is happening because all the objects are arguing over what the global hp actually is
I think this might be right....not sure though. I have 5 basic brains. One of them the collision works on, the other 4 it doesn't. Always. It wouldn't have that same behavior if the problem was that
they arguing on which global to use. Not to mention, and this is the important part, there is only one using that global hp. That's for the castle and there is never more than one castle. Also,
my brains have their own hp.



global.castle_hp -= 200

Ok. I'm convinced its nothing to do with the GML. But I will try and use GML for the collision detection as well and see if that works.

That's the only line of code that is executed in that event. Now there is another event, in the DraculaCastleObject that defines what happens when the castle is damaged, but that's not all of the problem
since that line, the global.castle_hp -= 200 never executes. I know that because the debug message never executes.


GML:
show_debug_message("BigBrainObject in DraculasCastleObject")
global.castle_hp -= 200
 
Last edited:

kburkhart84

Firehammer Games
Its good that you put the debug message there. It proves that the code is never running, and that the issue has to do with the collision being detected(unless the code is in the wrong place, it should be in the collision event of one of the objects). But good on you for taking that first step at the least.

The next step is to figure out why the collision event isn't hitting. Just for giggles, try changing the collisions masks both to full image, nothing precise at all, and see if that changes it. It won't be accurate for the collisions, but it will prove that the masks are at fault(or not).
 
Are DraculaCastleObject and DraculasCastleObject two different objects, or is one a typo?
Oops. Typo. It is DraculasCastleObject
The next step is to figure out why the collision event isn't hitting. Just for giggles, try changing the collisions masks both to full image, nothing precise at all, and see if that changes it. It won't be accurate for the collisions, but it will prove that the masks are at fault(or not).
That's my next best guess. I've tried it both ways - DraculasCastleObject as the main object and the brains like the SImpleBrain as the main object.

I'll try changing the mask.

(edit)

Ok so this is interesting. One of the brains was working before when the others wreren't. SimpleBrain its called. I changed the masks to full image, rectangle. Now SimpleBrain is stuck at the entrance to the castle where he spawns and just spins doing his walking animation. The others that weren't working aren't doing anything different.

To clarify, the castle he is spawned at isn't the DraculasCastleObject, its the enemy castle.

(edit)

I moved the spawn point for the stuck brain. There has been no difference in the collisions.
 
Last edited:
@Nidoking I tried using parents (BrainParentObject) and (SpecBrains) but that didn't work (there was no collision - i could tell because the debugging statement didn't show up) so I reverted it back to testing each brain individually which didn't work either.

(edit)

What do you mean by using the same sprite for all of them? Do you mean using a parent and then using a mask from another sprite?
 
Last edited:
I mean you said when you changed one mask, some other object changed the way it behaved. Why would that be? Why would changing a sprite affect something that doesn't use that sprite?
Maybe I misspoke. When I changed the masks I changed them for all of the brains. No change for all the brains except that one that got stuck on spawning. I made it spawn a little bit frontwards and now it doesn't get stuck.

(Update)

For some reason I haven't figured out yet another of the brains started working properly. Now I have two brains that do damage to the castle and the other three are like they've been, they just vanish when
they hit the castle.

(edit)

It seems like there is a collisiosn but it just doens't do damage. On the other hand, the debug statements indicate that there is no collision. I went through it with the debugger and it didn't break at the breakpoints
for the collision code.
 
Last edited:
Top