using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NejikoController : MonoBehaviour {
CharacterController controller;
Animator animator;
Vector3 moveDirection = Vector3.zero;
public float gravity;
public float speedZ;
public float speedJump;
// Use this for initialization
void Start () {
//필요한컴포넌트를 자동취득
controller = GetComponent<CharacterController>();
animator = GetComponent<Animator>();
}
void Update ()
{
//지상에 있을경우에만 조작한다
if (controller.isGrounded)
{
//input을감지 앞으로전진
if (Input.GetAxis ("Vertical") > 0.0f)
{
moveDirection.z = Input.GetAxis("Vertiacl") * speedZ;
} else {
moveDirection.z = 0;
}
//방향전환
transform.Rotate(0, Input.GetAxis("Horizontal") * 3 , 0);
//점프
if (Input.GetButton("Jump"))
{
moveDirection.y = speedJump;
animator.SetTrigger ("Jump");
}
}
//중력만큼의힘을 매프레임에 추가
moveDirection.y -= gravity * Time.deltaTime;
//이동실행
Vector3 globalDirection = transform.TransformDirection(moveDirection);
controller.Move(globalDirection * Time.deltaTime);
//이동후 접지하고있으면 Y방향속도는 리셋
if (controller.isGrounded) moveDirection.y = 0;
//속도가 0이상이면 달리고있는 플래그를 true로한다
animator.SetBool("Run", moveDirection.z > 0.0f);
}
}
지금 유니티에서 실행중인데 키보드 위를 누르면 캐릭터가 전진을 해야하는데
전진을 안합니다
Vertical이 setup안됫다는데 무슨의미인지 모르겟는데 혹시 여기서 캐릭터를 앞으로 움직이려면
어케하는지 예제좀적어주실분있으신가요 ㅠ
| Vector3 globalDirection = transform.TransformDirection(moveDirection); | |
controller.Move(globalDirection * Time.deltaTime); 이게 이동아닌가요 |
댓글 0