Gravity Death Fall not working?

I am working with physics2 it is really fun. I made a piece of code where if the player linear velocity (Y) is greater than 1000 and if the player happens to collide with the floor on that moment, I want to subtract 1 point from his current health.

Well at least that was my intention, but it turns out there’s something I don’t understand because it never subtracts the point from my character.

Edit: it works if you are touching the wall and falling at the same time but that is not what I intended. Any ideas on how to make it work as intended?

Do both objects have the physics behavior? The physics behavior has its own collision condition that only works with other physics objects. The regular collision works with both but I would use the physics on both and set the floor to “static”. Just in case you don’t know, the physics behavior has its own collision mask. Also, physics and platform behaviors don’t always play well with each other.

yes both have physics behaviour
platform: static
player: dynamic

no other behaviours are activated

1 Like

I am thinking it has to do with the linear velocity actually going negative when you bounce for a second
so i am going to try to store the linear velocity somehow but man this is tough

Yeah. It can take time to understand the physics behavior. I still don’t have a good understanding of the physics joints. Ordinary physics isn’t too bad. You’re toggling the Boolean pretty quickly on collision. It’s just going to give a quick blip for like 1 frame. Maybe you can skip the last 2 events and just add the collision condition to your velocity event and a trigger once.

Ignore that, the velocity is zero when it collides.

Maybe something like this.

I’m playing along and this works nicely. I used a sound file to test it. I changed it to plain velocity and added abs() (absolute value) I also added it to a text object just to monitor the value.

Last edit. I’m out of here. - the collision isn’t really needed with a trigger once.

1 Like

I have done something similar and it is a little cursed LOL
I have to try yours. Although yours would also work if the player hits his head on a platform as well right? (I mean going up)

So mine looks like this:

Sometimes it freezes my pc and sometimes it just doesnt work at all? But most times it does…Oh well this is not easy…

Yeah. I’m not sure what you were trying to do. Mine triggered on any speed change over the limit and collision with platform. When I tested it I used the same platform for the floor and the walls. With the sound action it worked so of like a sound effect but only if the speed was about a set number. I can’t really see how this type of code works. I need to see it in action. Logic events are consistent. Physics are less predictable. I’m not at my PC. So, I can’t help with this at the moment. Good luck.

1 Like

it’s fine you do a lot for me already!! I’m so glad you answered

Finally I decided to change my code and I am satisfied how it works, but I have a new problem now, I want to set a limit and if the player goes over it, he just dies regardless of life points, but it isn’t working.
It works if the velocity in Y stays between 1000 and 1500, subtracting 1 point from player’s life but I would love it for the player to die past 1500.

1 Like

You have the event that if falling velocity is < 5000, then set it to 1

In the next line, you check if falling velocity > 1500 and falling velocity < 5000. But the previous event will have set the falling velocity to 1, and so the condition will never be true.

1 Like

thank you for the observation I’m still battling to get it right haha

I decided that player death is more important so right now as it is, if you get past 1500 linear velocity you just die. This is actually one of the most fun things I ever coded, I will show you guys my idea soon.

Also, I’d suggest you change you change the event order - set fallingVeolcity as the last event, so it’s picked up just before the next game frame. The reason for this is that otherwise the player collides with the platform and velocity may already have been reduced by the physics engine. The result is that you’re picking up the impacted velocity.

If you get the velocity before the physics engine does its computations, then you’ll get the correct velocity value .

Additionally, I’d change the events to:

1 Like

This is so much better yes!! I still have to change it, but the code has changed a lot since I’ve been working many hours on it.

So…To separate what happens at 1000, 1500, etc…they need to be subconditions in order to work?
See I had never thought of that, so thank you very much I’ll have this in mind.

No, they don’t need to be, but it reduces the number of conditions and checks. And less checking by GDevelop usually equates to faster code. Admittedly nothing noticeable in this case, but if you get into that habit then a much larger game will be less likely to encounter lag with this principle.