Need solution to a moderately complex maths problem

I have a character with a beam weapon.

I also have a water system with no collision. The water system is is expansive and
applying collision to the water mesh is computationally heavy.

The water asset has a method to be able to get the height of the water wave at a given location.
image

My beam weapon performs a line trace on the visibility channel to find a hit where it will project the beam.

My issue is that since the water cannot be interacted with through any collision channel, I am unable to get the beam to stop at the water. The beam passes through the water and hits the ground.

I had a solution in mind but am unsure of the mathematical implication of it (i sux @ maths)

If my beam weapon is at location X=1, Z=4 and fires the beam towards water surface, which is at a Z height of 2 and my beam hits the ground at location X=6, Z=0, graphically I can see that my beam intersects the water at X=4, Z=2, and I would be able readjust the beam’s fire to this location on the water surface.

However, how would I go about achieving this in Unreal?

The only way I am able to interact with the water is through the “get wave height at location” function which I have so far used for almost every interaction by checking if whatever I need interaction with is at or around this height, thus, being able to cause splashes and turn on swimming.

Halp pls

I wonder what is a mathematically accurate waiting time before bumping a post…

Get the max length of the trace:

Beam


Hope it helps.

1 Like

Thank you @pezzott1 ! Absolute Maths God! <3

@pezzott1 I am having difficulty copying this. Could you provide the blueprint code for it?

Sure:

The math expression node doesn’t work with blueprintue.com so just copy it from the image above.

Ah that’s why my beam kept going towards world origin. Also my project keeps crashing at startup now. brb gonna try opening the blueprint and removing that maths expression

ok I reloaded a backup.

Do you know why my beam is going astray? It is atleast stopping at water surface now though.

This is my code for aiming the beam.

I’m probably doing something wrong here but can’t place my finger on it

OK I had misunderstood “Direction” It just wanted a unit vector.
image

OK I am now unable to aim above a certain point…

The BP shared only had the math you asked for.

Updated the blueprintue.com link above so that it can now also trace over the horizon.

1 Like

Thank youuuyu!!! <3 <3 <3

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.