在Unity中,我用这个脚本做了一个测试精灵,但是当我跳得快或者随机时我的角色掉在了地上,但是他在移动时保持慢,但是在跳/快速着陆。我的角色一直在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