LoginSignup
1
0

More than 1 year has passed since last update.

【unity】重力の無効化について

Posted at

はじめに

あるボタンを押下した際に、重力を無視して突進をしたいと思って実装したので、メモ。

内容

初めに、物理現象を無効化する方法(isKinematicを有効化する)を試したが、前後左右への移動すら無効化されてしまった。

重力の無効化(失敗例)
    void FixedUpdate(){

        ...

            // 重力を一時無効化する
            rb.isKinematic = true;

        ...

    }

そのため、y方向の速度を0にするという原始的な方法で実装した。

重力の無効化
    void FixedUpdate(){

        ...

            // 重力を一時無効化する
            rb.velocity = new Vector3(
                rb.velocity.x,
                0,
                rb.velocity.z
            );

        ...

    }

まとめ

物理現象の操作はよく行うので、覚えておいて損はないので、ぜひ調べていただけたらと思う。

参考文献

1
0
2

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
1
0