Hello everyone i recently found this github repository for dynamic gravity
however i need a component that could align any game object to the gravity direction so it always landed “on its feet” (without the camera and controls of the player for making other objects affected by gravity like npcs)
the issue is that it dosen´t work for some reason and thus i came here for support and help, what exactly am i doing wrong here?
You probably should use at least Rigidbody.rotation instead of Transform.rotation otherwise you can get some unwanted effects from the physics system. Though it’s “usually” better to use Rigidbody.MoveRotation to set a new target rotation.
You do a first fast, then slow transition due to your usage of Slerp. This may be what you want, but in many cases having more control over the speed is better. Especially since this non-linear approach suffers from acting differently at various frame rates. Rotating linearly Vector3.RotateTowards has the advantage that you have full control over how fast it rotates and that it actually reaches the up-right orientation. With Slerp it can take literally seconds if not minutes until the remaining angle disappears in the float precision. Recently I’m back playing SpaceEngineers and deactivating the jetpack while in a gravity field immediately rotates you up right. Not sure what their speed settings are but I think if you’re off by 180° it takes less than a second. It’s really useful to quickly align yourself to the gravity field while flying by just quickly deactivating the jetpack for a moment. That way you can accelerate perfectly upwards. Of course it depends on your actual use case. If you don’t ever have sudden changes (artificial gravity) it’s probably irrelevant.
Anyways, the rotation with RotateTowards would look like this