0
私はUnityにはかなり新しいので、どうやってそれが最良の方法ではないかもしれないが、キャラクターがジャンプするとそれは矛盾する。プレーヤーのバウンスが矛盾しているのはなぜですか?
いくつかのバウンスは、他よりもさらにたくさんあると私はなぜこれが起こっているかわかりません。
また上向きの矢印を押しても実際には非常に速くなりますが、数秒待つと正常なように跳ね返ります。その代わりに力を追加するrigidbodys能力を利用して、オブジェクトを翻訳する
using UnityEngine;
using System.Collections;
public class MovePlayer : MonoBehaviour
{
Vector3 endPos;
int numBackwards = 0;
bool jumping = false;
public Rigidbody rigidBody;
//public Collider theCollider;
void Start()
{
rigidBody = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
rigidBody.freezeRotation = true;
endPos = gameObject.transform.position;
if (!jumping)
{
if (Input.GetButtonDown("up") && gameObject.transform.position == endPos) {
if (numBackwards < 0)
{
numBackwards++;
}
else
{
UpdateScore.score++;
}
transform.Translate(Vector3.up * 50 * Time.deltaTime, Space.World);
transform.Translate(Vector3.forward * 110 * Time.deltaTime, Space.World);
}
else if (Input.GetButtonDown("down") && gameObject.transform.position == endPos)
{
transform.Translate(Vector3.up * 50 * Time.deltaTime, Space.World);
transform.Translate(-Vector3.forward * 110 * Time.deltaTime, Space.World);
numBackwards--;
}
else if (Input.GetButtonDown("left") && gameObject.transform.position == endPos)
{
transform.Translate(Vector3.up * 50 * Time.deltaTime, Space.World);
transform.Translate(Vector3.left * 110 * Time.deltaTime, Space.World);
}
else if (Input.GetButtonDown("right") && gameObject.transform.position == endPos)
{
transform.Translate(Vector3.up * 50 * Time.deltaTime, Space.World);
transform.Translate(Vector3.right * 110 * Time.deltaTime, Space.World);
}
}
}
void OnCollisionEnter(Collision other)
{
if (other.gameObject.CompareTag("Ground"))
jumping = false;
}
void OnCollisionExit(Collision other)
{
if (other.gameObject.CompareTag("Ground"))
jumping = true;
}
}
ですが、私は 'if'文の負荷を避けるために、あなたの' FixedUpdate() 'メソッド内で' switch'ステートメントを使用することをお勧め –
バウンスは依然として矛盾しています。あなたが上向きの矢印を本当に速く押すと、プレーヤーのバウンスが長くなり始め、最終的には前方に滑り始めます。 –