Finding the relative Down with rotation, and converting it to gravitational force.

Godot Version

v4.6.3

Question

Hello, Not sure if anyone can help me with this but I am working on a game, and have several other game ideas that involve gravity physics, and I found out you can change gravity using area nodes by inputting the direction you want the force to be applied in x , y coordinates but I want to be able to rotate an object and have it apply gravity to its relative down the most straightforward and useful way I can think of to do this would be to somehow convert the rotation into that x y Cordiant with math, but I cant figure how what equation would, or if one could even be made to do such a thing.
put as simply as I can my main goal is to convert rotation into gravitational force to actively control gravity to make “down” always be relative to the object being rotated.

anyone have any Ideas on how I could figure this out? or am I thinking about it all wrong?

I’m not amazing at math and I understand this may not be the best place to ask this question but I am hoping to fined either direction to some people who can help me or some better ideas that Godot specifically has that I may not know about that can achieve this more easily

Thank you so much for your time.

At the moment I just have a simple if statement doing this but I know math can do way better and allow more rotations

	if rotation_degrees == 0:
		gravity_direction = Vector2(0 , -1)
	elif rotation_degrees == 90:
		gravity_direction = Vector2(1 , 0)
	elif rotation_degrees == -90:
		gravity_direction = Vector2(-1 , 0)
	elif rotation_degrees == 180:
		gravity_direction = Vector2(0 , 1)

Use global_transform.x or gloabal_transform.y vector. If the object has scaling, normalize the vector before use.

I’d recommend you make a player controller with a CharacterBody2D and learn how get_gravity() works with different Area2D objects . Then play with RigidBody2D objects and the Area2Ds. You can do a lot of stuff with gravity without any math.

I think if you’ll do that, you will find much easier ways to implement whatever you’re trying to do once you get how they work. Plus you’ll have a better understanding of what math you need. Then, an easy cheat would be to put a RigidBody2D inside an Area2D. Put a Marker2D at the bottom of the Area2D, and get the gravity Vector every physics frame by just subtracting the Area2D position from the Marker2D position. No math needed other than subtraction.

Thank you so much for your help, your advice not only would have worked just as well as what I did and I plan to do future experiments with the marker node but setting it up helped me understand all the information global_transform was giving me and turns out simply gravity_direction = global_transform.y dose the trick perfectly!

Thank you for your help! I’m not 100% sure what the information global_transform is but it seems to be giving me exactly the numbers I want for the relative down and I can use this for a lot I think, plugging in gravity_direction = global_transform.y successfully gave me the ability to rotate my gravity zones without needing to set the gravity every time which is exactly what I wanted for my current project so thank you again, and ill keep the scaling thing in mind. But I think I can implement my above mentioned gravity controller with this as well.

global_transform is a Transform2D object that stores object’s global transformation matrix i.e. its translation, rotation and scale, in respect to global frame of reference.

x and y represent the basis vectors of object’s local coordinate system. You can think of them as those red and green arrows you see in the 2D editor when transforming objects.