Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: LookTargetControl でうまく回転させることができない #8

Open
nayuta-cr opened this issue May 2, 2024 · 0 comments

Comments

@nayuta-cr
Copy link

LookTargetControl で向きを変えたい場合、 Target と自身の y 座標に乖離があればあるほど、うまく角度が変わりません。
これは、 Vector3.SignedAngle() でヨーを計算する際に回転軸が傾いてしまうためです。

以下のパッチで修正することが可能です:

diff --git a/Packages/com.utj.charactercontroller/Runtime/Components/Control/LookTargetControl.cs b/Packages/com.utj.charactercontroller/Runtime/Components/Control/LookTargetControl.cs
index f81fd3f..36d456e 100644
--- a/Packages/com.utj.charactercontroller/Runtime/Components/Control/LookTargetControl.cs
+++ b/Packages/com.utj.charactercontroller/Runtime/Components/Control/LookTargetControl.cs
@@ -52,6 +52,7 @@ namespace Unity.TinyCharacterController.Control
                     return 0;

                 var delta = Target.position - transform.position;
+                delta.y = 0;

                 return (delta.sqrMagnitude > 0) ?
                         Vector3.SignedAngle(Vector3.forward, delta, Vector3.up) :
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant