error:当旋转之后,方向是发生变化的。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
enum characterOrientation
{
NUll,
UP,//面向摄像机 设为初始 1
RIGHT,
DOWN,
LEFT,
LENGTH
}
public class Character : MonoBehaviour
{
public float speed = 1.0f;
//前一个朝向
private characterOrientation aheadOri = characterOrientation.UP;//up
private characterOrientation ori;//若不设置 默认为0
// 初始化摄像机和人物的偏移
private Vector3 offset;
void Awake()
{
offset = Camera.main.transform.position - transform.position;
}
void Update()
{
#if UNITY_EDITOR
if (Input.GetKey(KeyCode.W))
{
Unity的角色移动代码(二)正误对比--大神请绕
本文通过对比分析错误代码,详细解释了Unity中角色移动的实现方式,重点关注了旋转和移动的方向计算,以及如何避免错误的发生。修复了错误代码中的问题,包括正确的朝向更新和旋转计算,确保角色按预期移动。
摘要由CSDN通过智能技术生成