UnityでVRゲーム作成 その12 ジャンプする
ぽめぽめぴくたんをジャンプさせる
・prefabにCharacter Controller と Rigidbodyをくっつける
・スクリプトを作成
using UnityEngine;
using System.Collections;public class jumpSample : MonoBehaviour {
private CharacterController controller;
private Vector3 moveDirection;void Start () {
controller = GetComponent<CharacterController>();
}void Update () {
if (controller.isGrounded) { //地面についているか判定
if (Input.GetMouseButtonDown(0)) {
moveDirection.y = 20; //ジャンプするベクトルの代入
}
}moveDirection.y -= 10 * Time.deltaTime; //重力計算
controller.Move(moveDirection * Time.deltaTime); //cubeを動かす処理
}
}
moveDirection.yの値を小さくしておくとあんまり跳ねない
引用 Unityでキャラクターをジャンプさせる方法[初心者向け]https://techacademy.jp/magazine/9321