实验目的
让导入的人物模型动起来
实验要求
实现人物操纵运动
实验环境
PC机,Unity3D软件
实验内容
一、下载相关资源包:
二、对人物模型进行相关设置:
三、创建人物控制文件:
四、创建人物动作流程序列:
1.增加站立姿态
2.增加行走姿态:
3.增加跑步姿态:
4.设置姿态间的跳转:
5.为每个动作设置触发阈值:
注意S要大写(与代码中一致)
五、编写控制脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class manMove : MonoBehaviour
{
public float speed = 3;
Animator anim;
Vector3 move;
void Start()
{
anim = GetComponent<Animator>();
}
void Update()
{
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
move = new Vector3(x, 0, z);
transform.LookAt(transform.position + new Vector3(x, 0, z));
transform.position += new Vector3(x, 0, z) * speed * Time.deltaTime;
UpdateAnim();
}
void UpdateAnim()
{
anim.SetFloat("Speed", move.magnitude);
}
}
六、添加人物视角:
简单测试一下效果:
可见,人物会穿模
七、给人物添加刚体效果:
点击视窗中最下面一个工具,然后点击人物外侧绿色线条上的点调整大小
七、给房子添加刚体:
两个拥有刚体的物体间会碰撞,就不会产生穿模了