下記のサイトの一番上のような重力の挙動をCharacterControllerを用いて行いたいと考えております。
http://ftvoid.com/blog/post/738
そこで下記プログラムを作成したところ、自身がgravTarget(球)に衝突したのちに球の頂点へ移動してしまいます。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Gravity : MonoBehaviour {
const float gravity=9.8f;
public GameObject gravTarget;
CharacterController characterController;
void Start () { characterController = GetComponent<CharacterController> (); } void FixedUpdate () { Vector3 gravDirection = gravTarget.transform.position - transform.position; //gravDirection.Normalize (); gravDirection.x = gravDirection.x + gravity * gravDirection.x * Time.deltaTime; gravDirection.y = gravDirection.y + gravity * gravDirection.y * Time.deltaTime; gravDirection.z = gravDirection.z + gravity * gravDirection.z * Time.deltaTime; characterController.Move(gravDirection * Time.deltaTime); }
}
どのようにすれば上記のサイトのような挙動になるのでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/02/08 10:26