Download

How to detect water in front of the characer

Hi guys, here is my situation:

I have a character that works with the ALS plugin and it works great, but I still have a problem that I couldn’t solve. I would like my character to dive into the water when the player jumps to a water spot. The problem is that I haven’t found a way to know if there is water in front of the player while respecting the following constraints:

  1. The water mesh would be procedurally generated, so the trigger box is probably not the answer.

  2. I would have some cliffs, so the height difference between my character and the water mesh is unknown.

  3. The world would be dynamic and could change during the game, so the place of the water points too. It should not be an actor placed in the world, but really a detection with the character plan.

I thank you in advance, it’s been a week that I tear my hair out on the subject and can’t find any solutions.

a line trace angled forward that looks for material. And let it be really long.

You tried something like that?

1 Like

Yes, but it’s too imprecise, the angle needed for the situation changes, so it doesn’t work. I need something with a margin, as if there was a point in the cylinder in front of me, but without a cylinder.er.

I’m not sure what the issue is, can you expand on this? I understand what you’re trying to accomplish in broad strokes but I don’t understand why line trace isn’t appropriate for this scenario.

There are also different types of traces besides line - there are box or sphere traces which provide more complex shapes that could provide you with more options for your application.

This code asset accomplishes context-sensitive diving animations, but I think the way it does so is based on line traces. You could take a look, but it might not solve the issue you’re experiencing.

1 Like

Thank you for your response, but I don’t see a link to a code asset in your response. Also, i am currently esting these complexe traces.

Whoops, copied and forgot to paste :stuck_out_tongue: Easy Swim Component - Create/Add Swimmable Water Volumes - Swimming Animations in Blueprints - UE Marketplace

It would certainly help me, but I try to do my own little game. And that, without buying anything.
I know it seems difficult, but for now it’s only for me and my friends, the game is not advanced enough to share it.

You can do a box or cylinder trace and make it larger. turn on debug on the node and you can visually see how big it is, what it hits, etc.

I tried the CapsuleTrace, but there is still some problem :

  1. I don’t want my capsule to collide with the characters, neither with the actors that aren’t water mesh.

I toughts, maybe 2 capsule that look forward with a different angle would do the job.

But I research a solutions that work every time.
It’s gonna be hard to finish my game.

Create a custom collision channel.

yeah I think there is already a premade channel just for water.

But the idea is that you can mark different types of things for different types of collisions. So in this case your capsule will only look specifically for items marked “water”.

This is just how game development is. Computers are idiots so you have to go to great lengths to explain every detail to them :).