Calculating intersected area

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ATaciturnGamer
:warning: Old Version Published before Godot 3 was released.

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.

:bust_in_silhouette: Reply From: kidscancode

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

Are you using a rectangular CollisionShape on your bodies?

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

ATaciturnGamer | 2017-09-06 03:48

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.

kidscancode | 2017-09-06 04:55

I’ve updated the question. What I want to do is calculate bouyant force. Details are given above.
Please let me know if you have an answer.

ATaciturnGamer | 2017-09-07 03:50