最近跟着UnityLearn做一个小游戏,发现官方另一种人物走法比我以往写的要更加顺滑
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
Vector3 p_Movement;
Quaternion p_Rotation = Quaternion.identity;
Animator p_Animator;
Rigidbody p_Rigidbody;
AudioSource p_FootAudio;
/// <summary>
/// 旋转速度
/// </summary>
public float rotaSpeed=20f;
// Start is called before the first frame update
void Start()
{
p_FootAudio = transform.GetComponent<AudioSource>();
p_Rigidbody = GetComponent<Rigidbody>();
p_Animator = GetComponent<Animator>();
}
// Update is called once per frame
void FixedUpdate()
{
float horizontal = Input.GetAxis("Horizontal");//获取横向,最大为1
float vertical = Input.GetAxis("Vertical");//获取纵向,最大为1
p_Movement.Set(horizontal,0,vertical);//把横纵向值赋给一个vector3变量
//这个变量就是一个模向量
p_Movement.Norma