[Unity] 플레이어 시작(Riidboby 사용)
1, Player에 Righidbody 추가

2, 중력을 사용하지 않을 때Gravity의 지퍼를 뜯어낸다

3, Player Controller를 만들고 다음 코드를 기술합니다.
(아래 키보드를 누르면 입력)
PlayerController.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
float x;
float z;
public float moveSpeed = 2f;
Rigidbody rb;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
x = Input.GetAxisRaw("Horizontal");
z = Input.GetAxisRaw("Vertical");
}
void FixedUpdate()
{
rb.velocity = new Vector3(x, 0, z) * moveSpeed;
}
}
여기서 동작을 확인해 보세요.애니메이션 만들기
1, Animatior Controller, Player에 부속된 Animatior 만들기
(Player에 Animatior가 없으면 AddComponent에서 작성)

2, Speed의 매개변수를 만들고 MakeTransition을 설정합니다.각 Condition에서 Speed를 설정합니다.
TransitionDouratior가 0인 HasExitTime 검사를 취소합니다.


3, 다음 주석에 코드 추가
PlayerController.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
float x;
float z;
public float moveSpeed = 2;
Rigidbody rb;
//アニメーターを設定
Animator animator;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
//アニメーターを取得
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
x = Input.GetAxisRaw("Horizontal");
z = Input.GetAxisRaw("Vertical");
}
void FixedUpdate()
{
rb.velocity = new Vector3(x, 0, z) * moveSpeed;
//パラメータを取得
animator.SetFloat("Speed", rb.velocity.magnitude);
}
}
4, 애니메이션 순환이 원활하지 않을 때 LoopTime과 LoopPose의 검사를 확인합니다
Player 방향 변환
1, 다음 주석 섹션 추가
PlayerController
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
float x;
float z;
public float moveSpeed = 2;
Rigidbody rb;
Animator animator;
void Start()
{
rb = GetComponent<Rigidbody>();
animator = GetComponent<Animator>();
}
void Update()
{
x = Input.GetAxisRaw("Horizontal");
z = Input.GetAxisRaw("Vertical");
}
void FixedUpdate()
{
// 方向を取得
Vector3 direction = transform.position + new Vector3(x, 0, z) * moveSpeed;
// directionの方向に向く
transform.LookAt(direction);
rb.velocity = new Vector3(x, 0, z) * moveSpeed;
animator.SetFloat("Speed", rb.velocity.magnitude);
}
}
Reference
이 문제에 관하여([Unity] 플레이어 시작(Riidboby 사용)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/bu-ta/items/241563c7d16e28bb325d텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)