캐릭터 컨트롤러 스크립트를 만들고 있는데 모든 것이 잘 작동하고 있지만 일단 플레이어가 떨어지기 시작하면 갑작스러운 동작이 멈추는 문제가 있습니다.Unity에서 부드럽게 빠져 나옴 - C#
using UnityEngine;
using System.Collections;
public class CharacterController : MonoBehaviour {
public float inputDelay = 0.1f;
public float forwardVel = 12;
public float rotateCel = 12;
public float JumpHeight = 20;
public Vector3 Gravity = new Vector3 (0, -180, 0);
public bool CanPress;
private float jumpTime;
public float _initialJumpTime = 0.4f;
//[HideInInspector]
public bool isGrounded;
Quaternion targetRotation;
Rigidbody rBody;
Vector3 forwardInput, turnInput;
public bool HasJumped;
public Quaternion TargetRotation
{
get {return targetRotation;}
}
// Use this for initialization
void Start() {
Physics.gravity = Gravity;
targetRotation = transform.rotation;
if (GetComponent<Rigidbody>())
rBody = GetComponent<Rigidbody>();
else {
Debug.LogError("Character Needs Rigidbody");
}
// forwardInput = turnInput = 0;
forwardInput = turnInput = Vector3.zero;
}
// Update is called once per frame
void Update() {
GetInput();
//Turn();
if (CanPress == true) {
if (Input.GetKeyDown (KeyCode.Space)) {
HasJumped = true;
jumpTime = _initialJumpTime;
}
}
if (HasJumped == true) {
rBody.useGravity = false;
jumpTime -= 1 * Time.deltaTime;
if (jumpTime > 0) {
Jump();
}
else {
HasJumped = false;
rBody.useGravity = true;
}
}
}
void GetInput() {
//forwardInput = Input.GetAxis ("Vertical");
//turnInput = Input.GetAxis ("Horizontal");
forwardInput = new Vector3 (Input.GetAxis ("Horizontal") * rotateCel, 0, Input.GetAxis ("Vertical") * forwardVel);
forwardInput = transform.TransformDirection (forwardInput);
if (Input.GetKeyUp (KeyCode.Space)) {
//HasJumped = false;
}
}
void Jump() {
Vector3 up = transform.TransformDirection (Vector3.up);
GetComponent<Rigidbody>().AddForce (up * 5, ForceMode.Impulse);
}
void FixedUpdate() {
Run();
}
void Run() {
if (Mathf.Abs (10) > inputDelay) {
//Move
//rBody.velocity = transform.forward * forwardInput * forwardVel;
rBody.velocity = forwardInput;
} else {
//zero velocity
rBody.velocity = Vector3.zero;
}
}
void Turn() {
// targetRotation *= Quaternion.AngleAxis (rotateCel * turnInput * Time.deltaTime, Vector3.up);
// transform.rotation = targetRotation;
}
void OnTriggerEnter(Collider col) {
isGrounded = true;
CanPress = true;
}
void OnTriggerExit(Collider col) {
isGrounded = false;
CanPress = false;
}
}
내 캐릭터가 중력을 사용하여 X, Y, 회전에 대한 Z 제약이있는 강체 attactches있다 - 나는 점차 아래로 떨어 플레이어를 원하는이 내 캐릭터 제어기 스크립트입니다.
- 플레이어는 부드럽게 올라가고 부드럽게 떨어지지 만 두 사람 사이의 전환은 매우 갑작스럽고 갑작 스럽습니다.
도움 주셔서 감사합니다. :)
자신 만의 캐릭터 컨트롤러를 구축하고 있습니까? 왜 당신이 유니티 스탠다드 에셋의 일부로 내장 된 캐릭터 컨트롤러를 사용하지 않는지 궁금하다면 :-) – Tom
안녕하세요, @Tom, 저는이 모든 것을 학습 경험은 단결의 inbuilt 스크립트를 항상 사용하고 싶지 않고, 내 자신의 스크립트를 만들어 내 게임 요구에 맞게 스크립트를 변경할 수있는 옵션을 제공합니다. –