目前本人使用过的对象移动方法有以下几种:
使用playercontroller自带的move和simplemove
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerCotroller: MonoBehaviour
{
CharacterController player;
// Start is called before the first frame update
void Start()
{
player = getComponent<CharacterController>();
}
// Update is called once per frame
void Update()
{
//水平轴
float horizontial = Input.GetAxis("Horizontal");
//竖直轴
float vertical = Input.GetAxis("Vertical");
//创建成一个方向向量
Vector3 speed= new Vector3(horizontial *0.1f,0, vertical *0.1f);
Debug.DrawRay(transform.position ,speed, Color.red);
player.Move(speed* Time.deltaTime);
//或者player.SimpleMove(speed)
}
}
初次使用这两者的时候吓了我一跳,Move()移动速度太快了,加之本人很久没有接触C#了,总把0.2f写成0.2导致vrcto