+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 by (13 points)
edited by

1 Answer

0 votes

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


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.
Please let me know if you have an answer.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.