ユニティでは、このスクリプトでテストスプライトを作ったが、速くても無作為にジャンプしても、私のキャラクターは地面に落ちるが、着陸が速い。Unity3Dのバリアから私のキャラクターが落ち続ける
using UnityEngine;
using System.Collections;
public class code : MonoBehaviour {
//void FixedUpdate() {
/*if (Input.GetKey (KeyCode.LeftArrow))
{
int Left = 1;
}
if (Input.GetKey (KeyCode.RightArrow))
{
int Right = 1;
}
if (Input.GetKey(KeyCode.UpArrow))
{
}
*/
public float speed1 = 6.0F;
public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
private Vector3 moveDirection = Vector3.zero;
void FixedUpdate() {
CharacterController controller = GetComponent<CharacterController>();
// is the controller on the ground?
if (controller.isGrounded) {
//Feed moveDirection with input.
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
//Multiply it by speed.
moveDirection *= speed1;
//Jumping
if (Input.GetButton("Jump"))
moveDirection.y = jumpSpeed;
if (Input.GetKey (KeyCode.UpArrow))
moveDirection.y = jumpSpeed;
}
//Applying gravity to the controller
moveDirection.y -= gravity * Time.deltaTime;
//Making the character move
controller.Move(moveDirection * Time.deltaTime);
}
}
あなたは地面とあなたのキャラクターにコライダーをつけましたか? –
あなたは 'CharacterController'のコードを投稿しませんでした。 'isGrounded'が正しくフラグが設定されていないように見えるため、これは問題です。 – KingDan
@halfer私は彼が中を意味すると思う。 – Alox