写在剧情系统前介绍下Character System for Mecanim的使用,接上

37 篇文章 1 订阅

全身碰撞盒子及关节绑定,这里顺便提一下,人物拿武器其实就是在这里实现的,

==================================================大家好,我是本篇文章的主角,我叫分割线=========================================

我们看下这个叫ninjaSWORD的空预制件,其实它只是在手的部位定义了一个方向,我们拿武器是怎么实现的呢?我这里给大家一段代码

using UnityEngine;
using System.Collections;

public class Torch : MonoBehaviour 
{
	public bool canPickUp = false;
	public bool hasTorch = false;
	public bool isLit = false;

	public GameObject rHandSocket;
	// Use this for initialization
	void Start () 
	{
		rHandSocket = GameObject.Find ("RHandSocket");
	}
	
	// Update is called once per frame
	void Update () 
	{
		if(!hasTorch)
		{
			if(canPickUp && Input.GetKeyUp(KeyCode.E))
			{
				PickUp();
			}
		}
		else
		{
			if(Input.GetKeyUp(KeyCode.E))
			{
				Drop ();
			}
		}
	
	}

	void OnTriggerEnter(Collider other)
	{
		if(other.collider.tag == "Player")
		{
			canPickUp = true;
		}
	}

	void OnTriggerExit(Collider other)
	{
		if(other.collider.tag == "Player")
		{
			canPickUp = false;
		}
	}

	void PickUp()
	{
		//change the position of the torch to the rHandSocket
		gameObject.transform.position = rHandSocket.transform.position;
		gameObject.transform.rotation = rHandSocket.transform.rotation;
		gameObject.transform.parent = rHandSocket.transform;
		gameObject.rigidbody.isKinematic = true;
		gameObject.collider.enabled = false;

		hasTorch = true;
	}

	void Drop()
	{
		gameObject.transform.parent = null;
		gameObject.rigidbody.isKinematic = false;
		gameObject.collider.enabled = true;

		hasTorch = false;
	}
}
这是一款游戏中从地上捡起一个棒子做武器的源码,我们可以看到,这里的
RHandSocket和<span style="color: rgb(51, 51, 51);">ninjaSWORD其实是一个东西,,我们在代码中获取它,然后把它绑定在</span><span style="font-family: Arial, Helvetica, sans-serif;">gameObject上,也就是我们要捡起的武器上,这样武器就拿在手里了。</span>

==================================================大家好,我是本篇文章的主角,我叫分割线=========================================

分割线里的东西跟这个插件无关,只学插件的话可跳过不看,不过我觉得这段比插件更有用^_^,


默认玩家控制输入,当然你也可以自定义按键设置

5. Root Motion    :  

Mecanim's Root Motion is applied in OnAnimatorMove

mecanim根运动施加在OnAnimatorMove


正如你所看到的,我只用root于基本运动和战斗,游泳,攀登,飞行都在heroctrl中实现6.Animation Controllers :

我用了4个动画控制器的字符系统。herobaseheroclimbheroflyheroswim。这些可以交换的需求。


7. Body     Masks    好了现在开始我们讲有用的了,其实上面的一直都有用,不过看个人喜好了,不过这段真的有用

我们从ai那篇开始一直在讲动画,动画,怎么让化身动的呢?下面这段就注意了

遮罩

8.Animation Controller Parameters :动画控制


这些参数定义来控制过渡状态条件,代码控制在heroctrl里。如下面图


9. Retargeting to custom skinned characters :

自定义皮肤的特征:

上网下载一个模型,这个模型需要顶点骨骼绑定,最少需要有15个点绑定





好了,这里讲下avatar

AvatarMecanim的一个如此重要方面,它需要被配置地符合你的模型。因此不论自动Avatar创建失败或者成功,你都需要进入Avatar配置模式来确保你的Avatar是有效并且合适地配置了。你的角色骨骼匹配Mecanim的预定义骨骼结构并且模型是T字形姿势是非常重要的。

If theautomatic Avatar creation fails, you will see a cross next to the Configure button.

如果自动Avatar创建失败,你将会看到一个叉号出现在Configure按钮旁边。

Here,success simply means all of the required bones have been matched but for betterresults, you might want to match the optional bones as well and get the modelinto a proper T-pose.

在这里,成功简仅仅意味着需要的骨骼被匹配上了,但是为了获得更好的结果,你可能会想也匹配上可选的骨骼以及让模型进入一种合适的T字姿势。

Whenyou go to the Configure... menu, theeditor will ask you to save your scene. The reason for this is that in Configure mode, the Scene View is used todisplay bone, muscle and animation information for the selected model alone,without displaying the rest of the scene.

当你进入Configure...按钮,编辑器将会问你是否保存场景。之后进入Configure模式,场景视图用来单独显示指定模型的骨骼,肌肉和动画信息,不显示场景的其他部分。

Onceyou have saved the scene, you will see a new Avatar Configuration inspector,with a bone mapping.

一旦你保存了场景,你就会看到一个带有骨骼映射的新Avatar配置检视器。


Theinspector shows which of the bones are required and which are optional - theoptional ones can have their movements interpolated automatically. For Mecanimto produce a valid match, your skeleton needs to have at least the requiredbones in place. In order to improve your chances for finding a match to theAvatar, name your bones in a way that reflects the body parts they represent(names like "LeftArm", "RightForearm" are suitable here).

检视器显示哪些骨骼是需要的还有哪些骨骼是可选的-可选的骨骼的运动可以自动用插值计算出来。为了让Mecanim产生有效的匹配,你的骨架需要至少含有必须的骨骼在适当的位置。为了提高查找匹配Avatar的机会,可以使用反映身体部位的名称命名你的骨骼(像“LeftArm”“RightForearm”这样的名称都是合适的)。

If themodel does NOT yield a valid match, you can manually follow a similar processto the one used internally by Mecanim:-

如果模型没有产生一个有效的匹配,你可以手动按照类似Mecanim内部的处理方式做一下:

1.   Sample Bind-pose (tryto get the model closer to the pose with which it was modelled, a sensibleinitial pose) 
采样绑定姿势(尝试让模型更接近它建模时候的姿势,一个合理的最初姿势)

2.   Automap (createa bone-mapping from an initial pose) 
自动映射(从最初的姿势创建一个骨骼映射)

3.   Enforce T-pose (forcethe model closer to T-pose, which is the default pose used by Mecanimanimations) 
强制T字姿态(强制让模型更接近T字姿态,这是Mecanim使用的默认姿势)。

If theauto-mapping (Mapping->Automap) fails completelyor partially, you can assign bones by either draging them from the Scene orfrom the Hierarchy. If Mecanim thinks a bone fits, it will show up as green inthe Avatar Inspector, otherwise it shows up in red.

如果自动映射(Mapping->Automap)完全或者部分失败,你可以通过从场景或者体系结构视图拖拽它们来赋值到骨骼。如果Mecanim认为骨骼合适,它会用绿色在Avatar检视器中显示,否则会以红色显示。

Finally,if the bone assignment is correct, but the character is not in the correct pose, you will see the message"Character not in T-Pose". You can try to fix that with Enforce T-Pose or rotate the remaining bones intoT-pose.

最后如果骨骼被正确赋予了,但是角色不是在正确的姿势,你将会看到消息“Character not in T-Pose(角色不是在T字姿态)。你可以尝试Enforce T-pose(强制T字姿态)或者旋转余下的骨骼到T字姿态。

Human Template files 人体模板文件

Youcan save the mapping of bones in your skeleton to the Avatar on disk as a"human template file" (extention *.ht), which can be reused by anycharacters that use this mapping. This is useful, for example, if youranimators use a consistent layout and naming convention for all skeleton butMecanim doesn't know how to interpret it. You can then Load the.ht file for each model, so that manual remapping only needs to be done once.

你可以用人体模板文件”(扩展名*.ht)的形式保存骨骼到你Avatar骨架的映射到到磁盘上,你可以在任意角色上重用这个映射。这非常有用,比如,如果你的动画使用一致布局和命名约定到所有的骨架上但是Mecanim不知道如何解释它。你可以为模型载入.ht文件,这样手动重映射只需要做一次。

----------------------------------------------------------------------上面这段是unity的官方文档,我这里做引用-----------------------------------------

1)设置切换本地视图对象上看旋转。你的角色会用这个来在右旋转爬。

2)的climbobject层应该是9层的“爬”。攀登系统会寻找这些层。

3)climbobject规模:X可以缩放到适合你想爬上几何。你必须为1,必须是1

4)climbobject尺寸:(对撞机)X必须为1,可以适合你爬几何。(保持leftshift拖动这些小绿点)Z可以适合你爬几何。(保持leftshift拖动这些小绿点)的climbobjects枢轴应在你想爬上边缘的最高水平。对其他climbobject类型唯一的区别,如climbobjecttop的名字,这触发不同的行动。

 

名称“watertrigger”是用来找到对象上触发输入。

这层水可以很方便的是某些情况下,但不是必须的。

对撞机必须设置触发。

1)   CollisionLayers : 碰撞层,相机应该撞击并排除层,相机不应碰撞。

2)   HeroHeight : hero高度

3)   HeroDistance : 默认的距离相对于人物

4)   MinDistance : 最小距离相机可以对于人物

5)   MaxDistance : 最大距离相机可以对于人物

6)    Zoom Rate : 如何快速,我们可以用鼠标滚轮缩放,默认情况下。

7)   ZoomDamping:如何顺利应该变焦

8)   Xspeed: 相机的X轴转速。

9)   Yspeed: 相机的Y轴转速

10)  Invert Mouse Y : 将鼠标的摄像机垂直旋转。

11)  Rotation Damping : 能顺利进行,相机的旋转。

12)  Offset from Wall : 相机的绑定的距离,碰撞时的视图中的远程对象。

13)  Fps Cam Dist : 第一人称相机距离的骨头

14)  Use Idle Orbit : 如果摄像机切换到轨道模式而品格在空闲动画

15)  Cam State :3种模式.First-person, Third-person and Orbit mode.

16)  Cam : 我们想要使用相机的参考指定相机拖动

1)   HeadBone : the head bone of our character. 头骨拖动

2)   MinAngle Y : 最小的角度我们可以垂直旋转

3)   MaxAngle Y : 我们可以垂直旋转的最大角度。

4)   CamInput : 一类是摄像机输入可见。方便的时候来设计调试

5)   mx:

鼠标X轴指示器。

6)   MY: 鼠标Y轴指示器。

7)   MSW: 鼠标的滚动轮上的指示。

8)   DFPS:第一人称模式触发。

9)   Do3rdP : 第三人模式触发。

10)  Do Orbit : 轨道式触发

11)  Do Lshift : 左转向指示

HeroCtrlsetup.

调整后的碰撞与字符连接你喜欢的,你可以检查可以看到(使)上

heroctrl脚本。

按播放,让素质下降更大的距离(约3米)。它应属于物理

站起来,你应该把你的时间,玩一会;-)

完结,有点多,下一篇我们来比较下现在市面上比较主流的做游戏的剧情工具的优缺点,这个剧情系统的更新可能要维持一周的时间,篇幅会相当长。谢谢继续关注。。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值