人物的移动:用刚体控制移动
声明角色移动的速度和刚体组件,用MovePosition()
让物体移动到新的位置position,恒速移动适用于频繁改变,推荐使用这种,较为平滑
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public float speed=6;//主角移动速度
private Rigidbody rb;//刚体组件
private float camLeagth = 100;//射线的长度
private LayerMask floorMask;//地面的层级数
//private int floorMask;
private Animator anim;
private void Awake()
{
}
void Start()
{
rb = GetComponent<Rigidbody>();//获取刚体组件
//floorMask =LayerMask.NameToLayer("Floor");
floorMask = LayerMask.GetMask("Floor");
anim = GetComponent<Animator>();//获取动画组件
}
// Update is called once per