Step1: 添加玩家角色动画
在Animator中 创建JohnLemon动画控制器
选中它,点击open
添加参数 Iswalking
然后添加 Idle 状态以及walking 状态
添加过渡关系
Step2:更改动画bug
1)人物会自动向上飘
Update Mode 不再默认状态,选择 Animate Physics
Freeze position 选中Y轴
Freeze Rotation 选中X,Z轴
Step3:玩家移动以及转向代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
// Start is called before the first frame update
//获取玩家输入,进行操控
//玩家转动
//考虑动画
Vector3 m_Movement;
float horizontal;
float vertical;
Rigidbody m_Rigidbody;
Animator m_Animator;
Quaternion m_Rotation = Quaternion.identity;
//旋转速度
public float turnSpeed = 20.0f;
void Start()
{
m_Animator = GetComponent<Animator>();
m_Rigidbody = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
horizontal = Input.GetAxis("Horizontal");
vertical = Input.GetAxis("Vertical");
}
void FixedUpdate()
{
//将用户输入组装成3D运动需要的3维矢量
m_Movement.Set(horizontal, 0.0f, vertical);
m_Movement.Normalize();
bool hasHorizontal = !Mathf.Approximately(horizontal, 0.0f);
bool hasVertical = !Mathf.Approximately(vertical, 0.0f);
bool isWalking = hasHorizontal || hasVertical;
//将变量传给动画管理器
m_Animator.SetBool("Iswalking", isWalking);
//用三维矢量来表示转向后的玩家角色
Vector3 desiredForward = Vector3.RotateTowards(transform.forward,m_Movement,turnSpeed*Time.deltaTime,0f);
m_Rotation = Quaternion.LookRotation(desiredForward);
}
void OnAnimatorMove()
{
m_Rigidbody.MovePosition(m_Rigidbody.position + m_Movement * m_Animator.deltaPosition.magnitude);
m_Rigidbody.MoveRotation(m_Rotation);
}
}
Step4:添加场景以及光照
点击 Directional Light
改变 Type
点击windows rendering,设置环境光照
Step5:设置导航
windows -- AI -- Navigate
选中Level 点击static
选择ceilingfloor 然后取消static勾选
Step6:选择照相机跟随
cinemacamera --- virtual camera
调整 Rotation 45度
选择主人公跟随
Body Framing Transposer
Aim Do nothing
Camera distance 6
你之前写的游戏是用Ruby写的吗
都是c sharp
嗯,太厉害了
Ruby我还不会,django课也用过python和js写过网页游戏
hhhh,现在素材非常丰富,其实自己就写写代码,以后还要专门去学动画做素材
这是用Ruby写的?
csharp
这是unity吗
嗯嗯,这是unity
太厉害了
y总十月底就要教unity,我提前预习一下