从旋转到旋转故障我的角色控制器

From to Rotation Glitching My Character Controller

所以我正在制作一个角色控制器,它使用 Quaternion.FromToRotation 将玩家与这段代码中的重心对齐:

this_body.transform.rotation *= Quaternion.FromToRotation(this_body.transform.up,gravity_up);

当我在球体行星的某些部分时,它开始到处翻转,就像在 this 视频中一样,我不知道如何解决这个问题,尽管重力实施可能是问题,或者角色控制器,虽然我认为使用相对力不应该弄乱它。

重力实现:

float distance = direction.magnitude;
float forceMagnitude = G * (obj.GetComponent<MultiAttractor>().rb.mass * rb.mass) / Mathf.Pow(distance, 2);
Vector3 force = direction.normalized * forceMagnitude;
rb.AddForce(force); 

我的角色控制器脚本有点长,所以我认为我不应该让您感到厌烦,但如果需要我可以提供。

这适用于使用 Quaternion.FromToRotation 和刚体角色控制器时遇到问题的任何人:

I did not dig much into your problem but you are manipulating the rotation directly in the code with Quaternion.FromToRotation and also with physics. I think you need to stick to one of the two, because using both might lead to unexpected behaviours. If you introduce a "raw" rotation modification, the physics engine deals with it. – rustyBucketBay

基本上只使用像 Rigidbody.rotation for rotating things like Transform.Rotate or if you want to rotate physics objects like you are adding force, but instead of moving things it rotates things, then use Rigidbody.AddTorque 这样的物理旋转,或者只是不要将任何物理旋转与其他类型的旋转一起使用,因为它可能会导致问题,如 rustyBucketBay

所述