概要
UnityちゃんのモデルをAsset Storeからダウンロードし、
モデルデータにRigidbodyとCapsule Colliderと下記スクリプトをセットしました。
壁としてCubeを配置しました
この状態でジャンプ中に壁ぶつかるように動くとキャラが空中で止まってしまいます
Physic Materialを摩擦0にすると止まらないようになりましたが今度は
その壁の上でキャラを動かすとつるつる氷のように滑ってしまいます。
壁の上も歩けるようにかつ壁にぶつかってもちゃんと重力が働くようにすることはできないのでしょうか?
説明が難しかったためプロジェクトデータを貼ります
Assets -> Scene -> RigidTestというのが余計なものを省いた再現できるシーンになります
https://drive.google.com/file/d/0B0Yp3Kjg8wMZdmxyMW1PSlhFWnc/view?usp=sharing
よろしくお願いします
イメージ画像
スクリプト
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class Player : MonoBehaviour { [SerializeField] private float movement = 1000f; [SerializeField] private float rotateSpeed = 90f; [SerializeField] private float jumpPower = 10f; float moveX = 0f, moveZ = 0f; Rigidbody rb; void Start() { rb = this.GetComponent<Rigidbody>(); } void Update() { moveX = Input.GetAxis("Horizontal") * Time.deltaTime * movement; moveZ = Input.GetAxis("Vertical") * Time.deltaTime * movement; Vector3 direction = new Vector3(moveX, 0, moveZ); if (direction.magnitude > 0.01f) { float step = rotateSpeed * Time.deltaTime; Quaternion myQ = Quaternion.LookRotation(direction); this.transform.rotation = Quaternion.Lerp(transform.rotation, myQ, step); } if (Input.GetButtonDown("Jump")) { rb.AddForce(Vector3.up * jumpPower, ForceMode.VelocityChange); } } void FixedUpdate() { rb.velocity = new Vector3(moveX, rb.velocity.y, moveZ); } }
補足
- Massを適当な値45や450にしても解決しませんでした
- Dragを0や1にしても解決しませんでした
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/09/19 03:15