i need to read the gravity of a rigid body but i want it to stay locked in a position how could i do that?
Godot: lock rigid body in place while reading gravity
Cinghialotto said:
i need to read the gravity of a rigid body but i want it to stay locked in a position how could i do that?
Gravity usually is a globally constant value in games, so why would you want to read it per body?
Even if it differs per body, then it's you who needs to set its value per body, so you should already know that value.
This makes me think your question is badly phrased. Maybe you want to get acceleration per body?
But even then, if the body is locked, meaning it does not move maybe because it's static, then acceleration (and velocity) is zero, so no need to read it either.
Probably you want to tell us more about what you try to do.
Idk which physics engine Godot is using, But usually the physics update is async with multi threading. Then you may need to sync to ensure the update is done before you can safely access body data.
There may be also a callback per body, where you can apply external forces. This callback could be used to read / modify body data, e.g. to set individual gravity per body.
@JoeJ in godot there is a node called area3d and in this node are you can have custom gravity. if a rigid body is in the area its gravity get replaced with area3d gravity,so my player is a kinematic body so it cannot sense the area3d gravity then i added a rigidbody to my player that act as a sensor,now this rigid body moves freely and i need it to stay in the same position of the player. i tried to use the freeze flag but it completely stop the pyshics calculation on the rigid body.
this is the code i used for getting the gravity direction vector3 acting on the rigidbody if it can help:
extends RigidBody3D
var gravity_direction_rigidbody : Vector3
func _integrate_forces(state : PhysicsDirectBodyState3D):
gravity_direction_rigidbody = state.total_gravity.normalized()
here the player node tree:
i tried axis lock but it bugs out. for the moment i'll try to re make the project in 2d and find the problem
i resolved i set the freeze flag and then selected kinematic and the bug was that i didn't setted up the collisison mask and layer lmao so i separeted the rigidbody collision shape cand haracterbody3d collision shape in two different layer
hmm... i'm not a game engine user, but it sounds your approach of coupling a dynamic and kinetic body is a work around that should not be needed.
I assume, from the perspective of the physics engine, the area3d is a trigger volume, and both kinetic or dynamic bodies should detect intersection with it.
So ideally there should be a way to get rid of the dynamic body just to serve as gravity sensor. I would be worried about side effects, e.g. collisions separating the two bodies. Might be worth to ask on Godot forums as well.
the area 3d can "overwrite" the rigidbody gravity,but i would like to use a characheter body, that doesn't get affected by gravity sadly . so i have 2 choice rewrite all as rigidbody controller or make a "custom" gravity script for the charachter controller,i made a collision and mask layer for all the nodes that interact with gravity area for not having problem ?