# How deep the character is in water physics volume?

Hi there.

I created a water physics volume and made my character swim in it. But I have two problems here.

1- When I MoveUp my side scroller character, when it reach the surface of water it jumps out of water a little, just for a tick or two and creates an unnecessary event for me. So is there something here to stop character from doing that?

2- I added launch from water but I don’t want to jump when character is too deep in water, just when it’s near the surface. So how can you find out where in the volume the character is?

P.S: Actually I can solve the first problem if I find a solution for the second.

Thanks

Get the bounds of the water, add the Z to the origin’s Z. That will give you the Z position of the surface of the water (if the origin is in the middle). Use get actor location on your character, get his Z, add that to the capsule half height of the capsule collider. That gives you the position of the bottom of your character. Take the first number and subtract the second number, that should give you how far in the water your character is. If you need a better explination, I’ll be home later today and I can get some pictures made.

Hi @rklsImmersion, thanks for the reply and sorry for delay. I was asleep all time! I understand the flow here but about getting the bounds of volume I’m not sure how to do it in Character BP, of course I can do a trace and find out about the volume but isn’t a better way?

old but a good question.

First of, I’m working it all in the character BP so there’s a bit of casting logic.

Secondly, I have the input axis movement that works as a different kind of OnTick function always checking to see if the character is swimming. This just sets a bool, and performs some setup logic when swimming - again, similar to what you would do OnTick without using OnTick.

IF the character is swimming (branch) I query the overlapping components, loop through them and isolate the water physics volume. Set it to a variable for later use.

This was later updated to use an event so it would not be ran every time the character was in a swimming state, but only on the overlap event with the volume itself. If your water has a BP you can make that logic happen there, if not, use the level map - you just need to call an event inside the CharacerBP for every begin overlap and end overlap with the physics plane. It makes it run smoother because it’s not always executing checks.

Moving on, From the isolated volume I get the world z and the box extent to do the depth mapping.

Current depth = world z + box extent z , - character position z.

this gives you the rough position that you can further adjust with the capsule size if needed.

after the math part I immediately check the value against a maximum depth allowed and call an event to apply damage over time as long as the depth is lower then it can be.

Hi MostHostLA
It’s a long time from when I wrote this question and I changed my gameplay so my characer launchs when she reaches the surface. But I have another questio though if you can help me with that.

Thanks