Unity 人物行走的另一种写法

最近跟着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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值