Vector math question

I have 4 points that move up and down with water waves in the project I’m making. Previously I used this to apply a force on an object at the location of said points, when they are submerged they would provide an upward force and when above the surface downward force. This was pretty easy and straight forward. Howerver due to complications and a different approach of gameplay mechanics I’m looking to replace the physics based model with a interpolated positonal model. Now in order to do this I have to the use locations of each point and somehow get a median vector as result.

Here is a gyazo of the 4 points which go up and down with the waves. Now what I need to get working is the white plate to tilt and move as if each end of the plate was one of the red squares. Basically make the plane move with the waves as it should if it was a boat.

I’m not that great at math and vectors this is some pretty complex vector calculating so I was wondering if anyone could give me a hand in this.

Thanks

I saw this approach, but I didn’t understand why 4 points used.
If you want to get a direction of boat Z vector, you must use 3 points to make plane, then get its normal.
Ok, if you want some more “precise” Z vector, you can use 4 points, get 2 planes with them, get their normals, and finally calculate some average Z vector. But in this case planes can be different, like different triangles in quad.

1483f91eb59290dae6fda984711496d35577f06c.jpeg

Ok thanks, that makes sense. From what I’ve found online about this approach is that I would need two normals like you say from each triangle. To get this I would need to do the cross product of of two vectors per triangle. That gives me the normals but how do I average out the two normals?

I’ve tried this and for some reason the cross product normal vector isn’t perpendicular to the two vectors that fed the cross product. Why is this?

This is my code


This is how the normal vector behaves

Am I right in using this approach?


Now I know that the plane / boat can never have each of its ends line up perfectly with the bouyancy points as that would sometimes cause the boat to twist on itself. But what I need is a proximity and average of the 4 points as close as possible.

Cross product needs direction, not location, so get rid of the vector addition. The vectors also need to be normalized before being plugged into cross product.

Try something like this:

Edit: You might need to swap around the pins that are plugged into the Make Rot from XY node.

Woah, thanks man. Going to try that first thing tomorrow. :slight_smile:

Had a bit of a go at this too using look at nodes.

Hmmm very interesting. Thanks!

I’ve tried ausernottaken approach first. And it works (almost)! :stuck_out_tongue:

There is just one problem, every now and then the flat surface flips around. It seems to inverse itself. Not sure why that is.

Look at the arrow, sometimes its above the water, sometimes its under it.

Also there is another problem, the flat surface doesnt seem to go sideways (roll) a lot if at all actually. It goes up and down with his nose and back, but the long sides don’t seem to be affected by the bouyancy points. So maybe it’s not advanced enough.

I had the same problem with ausernottaken’s approach too which was why mine was done differently, to be honest I did not attempt to figure out why it was not working, just went of on my own tangent - was fun to do though.

The flipping is probably because the vectors are not always 90° apart. Try this: