Physics Engine. De-Activate Physics 2 behaviour doesn't de-activate the object

This is trying to mimic the platformer example of jumping on a mob, deleting it, and making the dead body now not interactable with fade out over 1 second.

The issue is that it just doesn’t seem to work for me.

Activate behavior Physics2 of Enemy: no

Still makes it possible to interact with it after it’s dead.

The animation of the Dead body stays in spot, but the actual body is invisible, keeps moving and my character gets blocked by it and can stand on it.

How do i make it so that when i “kill the enemy” as in floorcheck is in collision with enemy
The enemy object moves to a non-interactable state, with the “Dead” animation. and fades out over 1 second?

I suspect the issue is not the physics behaviour, but the collision box. When an object is set to invisible, it’s just not displayed on the screen - it’s still there, but just not shown.

There are 2 simple[ish] ways you can deal with this:

  1. Add an boolean instance variable to your enemy to indicate whether it’s interactable, and then add a condition to the collision detections to check that it’s interactable.
  2. Create another object just for the death animation, so it has a different name and won’t trigger the collision conditions.

@MrMen Just to clarify for Rincewind (since we were trying to solve this on the discord)

The issue is that the enemy object is still interactable as a physics object even after the behavior has been disabled. Unless there is missing information (e.g. enemy objects have separate hitbox/collision objects attached to them that we’re not aware of), what they’re seeing happen is that the physics behavior has been disabled from the enemy, but the playerhitbox is acting as if it’s still on/touching/etc a valid physics object.

#2 was my suggestion as well, but the concern then becomes they have to create a “dead animation” object for every enemy type in the game.

@Silver-Streak, Thanks for the heads-up. I created a little test project of 2 objects, both with Physics 2 behaviour, one 1/2 a screen above the other.

At the start of the scene both started falling down. On a key press, the bottom one had physics behaviour turned off. It stopped immediately. The top object kept falling, passing through the bottom object, i.e. there was no physics interaction.

From this, I suspect it’s somewhere else in the OP’s code, or it’s the collision box that’s causing the problem

Can I ask how this has been confirmed, and how was it was shown to not be the collision box?

Just an FYI - when you create a tween, there’s the option to delete the object when the tween has finished. If you use this, you can do away with the event that checks if the tween has finished playing before deleting the enemy.

Does this mean i have to do this for every single enemy as well? just like the 2nd option?

It seems weird that it’s this complicated to remove interactability, For platformer object in the platformer example you need hardly anything

and most other code for it is pretty much just copy paste to work with physics engine with slight changes to it

I guess it’s just way more complicated in physics engine? :confused:

Yes. But I believe your issue lies elsewhere, and you can avoid all this hassle by sorting it out.

It’s fairly simple compared to what some games engines provide. But I think it’s a good fit for GDevelop. It provides basic, essential physics functionality.

So how exactly do i do this? i’m 2days into this so not exactly sure how you’d go about doing this in practice.

To the left of the object in the Objects panel, are 3 vertical dots. Click on that and select Edit Object Variables. Click “+ ADD”, give the variable a name and then click the spanner icon to change its type to a boolean.

To set it in the event actions, click add action, click on enemy, and then under Variables select “Boolean value…”.

Similarly, to add it as a condition for an event, click add condition, click on enemy, and then under Variables select “Boolean value…”.

How does this fix the issue though? i’m still going to be able to Interact with it since it’s a Dynamic physics object and so is my hitbox?

None of my interactions like stand on or push or such with the object is done through actions because both the player and the enemy are physics objects?

All this does is give me another action i can use as a condition for what happens when it dies, but i already have that in animation of enemy is dead, i dont need another condition. i need an action that removes interactability?

It won’t in this case, I only provided this answer because you asked how to do it.

If you’re stuck and nothing anyone has suggested works, you could consider zipping up the project and making it available for download, to make it potentially quicker and figure out what’s going on. You can PM me if you’re not keen on every man and his dog downloading it.

here’s the entire project so far

it’s really barebones so i dont mind sharing haha.

I would be super happy if there was some rather simple solution to the problem :slight_smile:

I really want a physics based platformer so i can do some fun stuff with pushing boxes off ledges, maybe swinging from grapple hook etc a bit like in Trine but solving how to interact and make enemies die properly is a rather basic start element for that.

Well, buggered if I understand why the physics collision box isn’t turned off when you disable physics. Other effects, like gravity, are removed, but that collision box isn’t. I’ve created a test project and it works fine. It’ll need a better investigation to what is causing it, so it’s potentially a bug.

I did manage a work-around though, by deactivating the physics collision layer and mask along with the physics behaviour. The collision layer and mask are used to determine what other objects to check for with regards to physics collision. If the mask of one matches the layer of the other, it tests for a collision. And if you don’t turn off the physics behaviour, the enemy character plummets like a stone off the screen:

Ideally you could do it like this, and set the delete flag on the tween creation:

And you may want to move the Jump object to the GUI layer :slight_smile: .

Thanks for all the help I appreciate it a lot :slight_smile: