0
나는 유니티에 대해 아주 익숙하다. 그래서 내가 어떻게하면 좋을지 모르지만, 캐릭터가 점프 할 때 일관성이 없다.왜 플레이어의 바운스가 일치하지 않습니까?
일부 바운스는 다른 것보다 훨씬 많으며 왜 이런 일이 발생하는지 잘 모르겠습니다.
또한 위쪽 화살표를 누르면 빠르게 움직입니다.하지만 2 초 정도 기다리면 정상처럼 튀어 오릅니다. 대신에 힘을 추가 할 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;
}
}
답변을 neaten하기 위해, 나는 문 if''의 부하를 방지하기 위해, 당신의'FixedUpdate()'방식 내에서'switch' 문을 사용하는 것이 좋습니다 것입니다 –
바운스가 여전히 일치하지 않습니다. 위쪽 화살표를 너무 빨리 올리면 플레이어가 튀어 오르는 시간이 길어지고 결국 앞으로 활공을 시작합니다. –