Hmm…
If you insist on using physics for this problem (either because you intend to have the system respond to external forces, or simply because you want to implement a physics-based solution), I’ll try to adhere to that.
Your current approach
From what I can gather, you’re using an Area3D
to apply local gravity around a point. In your code, you then seem to be cancelling this gravitational acceleration on your fish via a buoyancy force, Fb
.
# Fb is buoyancy force ish
var Fb := -mass * state.total_gravity
You didn’t describe what your current code produces in terms of motion. However, I assume that your fish (like in the post I linked previously) moves further and further away from the center of the sphere as time progresses.
With regards to basis manipulation, that looks fine - classic cross product use.
Also, you seem to be handling force-computation just fine. I’m not sure if it’s valid to call apply_central_force
directly. I believe the whole point of using integrate_forces
is to get access to the state
of the body so you can safely manipulate it. In other words, I’m not sure whether the following counts amounts to the same outcome - it might.
# Your code
apply_central_force(Fb + local_fwd)
# Correct usage (?)
state.apply_central_force(Fb + local_fwd)
take that with a grain of salt
Recommended steps
From your code, it doesn’t look like you considered the solution in the post I linked. The concept that you have to apply is pretty much identical. The only thing that is different (and that is slightly) is the implementation because you’re using a RigidBody3D
, not a CharacterBody2D
.
Therefore, I would recommend the following steps:
- Read through the linked post and note down the concepts or code you don’t fully understand
- Look closely at the post’s provided solution and try to determine how you can use it for your problem
- If you are still unable to solve the problem at this point, please provide a description (video/gif would be preferred) of what your system is doing and what you’ve tried to fix it.
I’ll try and catch you tomorrow, during the time of your next reply, so we can expedite your issue and find the solution.