Updating players gravity based on spaceships rotation struggles

Godot Version

4.4 rc1

Question

hello friends. i have a particular problem im really struggling with. I have a spaceship in my scene which always sits at 0,0,0 and moves the world instead of moving itself. the ship itself does rotate on it’s own axis. i have a player that when inside has their rotation updated so the player rotates along with the ship as they would. My issue is with applying gravity to the player once the rotation has happened.

If the ship is inverted 180 either on the X or Z axis my code works but if any random rotation like 90 degrees in either X or Z or a combination of other rotations the player will fall towards one of the ships walls.

player.velocity += -ship.global_transform.basis.y * 9.8 * delta

im happy to share any of my current code but the line above seems to be the one that im clearly not undertstanding properly.

If this is in 3D, shouldn’t that be:

player.velocity += -ship.global_transform.basis * 9.8 * delta

That is, I think you want to transform it by the entire basis, not just by one component of the basis.