0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[Unity]TransformのPositionのYを0にしたのにキャラクターが浮いてしまう事象の解決例

Last updated at Posted at 2020-12-29

どんな状態だったか

1枚目の画像のように、inspector内のtransformのpositionのyを0に指定したのに、2枚目の画像のようにキャラクターが浮いてしまいました。

↓0に指定したのに再生ボタンを押すとYが1.43になってしまう。
スクリーンショット 2020-12-29 13.32.54.png

↓実際に浮いてしまっている様子。
スクリーンショット 2020-12-29 13.32.25.png

原因

CharacterControllerの衝突判定をしているHeightをキャラクターより大きくして、はみ出た部分を地面埋め込むように設定していたのが原因でした。

↓衝突判定の楕円が地面にめり込んでしまっている様子。実際はめり込まずにキャラクターを押し上げてしまう。
スクリーンショット 2020-12-29 13.42.16.png

解決方法

CharacterControllerのCenterとHeightの数値を調整して、下記の図のように衝突判定のエリアが地面にめり込まないようにすることで解消できます。

スクリーンショット 2020-12-29 13.44.11.png

ちなみに筆者の場合はキャラクターの全長が0.8だったので、下記の図のようにCenter = 0.4,Height = 0.8 としたら浮かばず接地した状態にすることができました。

↓Center = 0.4,Height = 0.8とした。
スクリーンショット 2020-12-29 13.50.11.png

↓修正後に接地できていることが確認できる。
スクリーンショット 2020-12-29 13.49.36.png

参考

CharacterControllerの細かい説明は下記のサイトに記載があるので興味があればみてみてください。
公式リファレンス:
https://docs.unity3d.com/ja/2019.4/Manual/class-CharacterController.html

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?