+1 vote

So, I'm trying to calculate the area of the part of a boat submerged in water (2D)

Is there any easy way to do this using Area2D or CollisionShapes(any methods)? Or do I have to write my own algorithm?

I'm quite new to game development and Godot, so any help is appreciated.

Edit 1:
So, what I'm trying to do is calculate the buoyant force on a 2d ship in water. It's sort of an endless runner, and the water is a tilemap that's generated as you move. The ship is a just a sprite at the moment, and I have a rudimentary buoyancy effect working using the height of the sprite in water, but as it rotates it changes.
I considered using the rigidbody node at first, but I couldn't figure out the right balance, and I didn't know how to change speed upon hitting water.

So, what I want is a foolproof method to calculate buoyant force, no matter what changes I make elsewhere in the code.

in Engine
edited

You can use the Rect2 `clip()` function to find the intersection of two rectangles:

http://docs.godotengine.org/en/latest/classes/class_rect2.html#class-rect2-clip

Are you using a rectangular CollisionShape on your bodies?

by (21,971 points)

Thanks, but I'm not using Rectangles. I'm using a custom polygon.
Is there any way?

It might help if you gave some more details about what you're trying to accomplish (how your nodes are set up, what you want to do with this submerged area, etc). Sometimes you'll find that if you describe the situation, someone will give you an alternative that works even better.

I've updated the question. What I want to do is calculate bouyant force. Details are given above.