Energy Expenditure

Is there a way to subtract points from a player’s health if they are doing a certain action? So if a player swims or flies it uses more energy the more they swim or fly. It’s different than a collision since I don’t want a point subtracted every time they collide with the water or whenever they’re not on the ground.

The point of this is to discourage the player from flying the whole time since it uses more energy (this is an educational aspect of the game). I appreciate any input!

1 Like

how do you fly in your game? How do you swim in your game? What triggers or keys are used?

this might be for swimming. In proximity to the water, it will start subtracting one every (timer value) seconds from the energy score.

1 Like

I use raycasts based on where the player is:

  • close to the ground: they walk
  • not on the ground: they fly
  • near water: swim

This screenshot shows the walking and flying behaviors.

I added the code from your screenshot by connecting the raycast to the switch/timer, but the switch isn’t being triggered for some reason.

1 Like

Oop :sweat_smile:
I forgot to turn the switch to on, it has to start at on. These days for help requests I just write the code and don’t even test is out…. Lol

This is very helpful. I guess something else to consider is what happens when enegry runs out…. Or I can just make the code and you decide latet

Thank you! Your code works with the switch set to on, but it only seems to work the first time. After one instance of flying, the switch doesn’t turn on anymore. Do I need to connect something else so it is turned on when the raycast “misses”?

On the raycast hit → on switch I think

It would be much easier to do this if I had the game link…

but first add that

1 Like

That worked – thank you!