来源:蜘蛛抓取(WebSpider)
时间:2017-10-04 02:21
标签:
unity粒子加拖尾特效
当前位置: &
& Unity3D冲锋效果、角色拖尾效果的制作
Unity3D冲锋效果、角色拖尾效果的制作
类别:&&大小:8.08MB语言:简体中文&&授权:免费软件
在本场景用到的拖尾效果可以查看我的另一篇文章,里面有详细的介绍,刀光效果来自 Unity3D Assets 商店,只是把原作者的例子代码整理了一下,变得非常简单实用的类。 《魔兽世界》,本人最喜欢的网络游戏,如果你玩过战士,你一定对战士的冲锋非常熟悉,现在接触 Unity3D,因为最近用到了刀光、拖尾特效,所以就想做一个类似战士的冲锋效果,在本场景用到的拖尾效果可以查看我的另一篇文章,里面有详细的介绍,刀光效果来自 Unity3D Assets 商店,只是把原作者的例子代码整理了一下,变得非常简单实用的类。 最终效果如下: 先来搭建我们的场景,如图: 然后给角色的模型添加一个空对象,并且加上 MeshRender,并且设置好材质为 WeaponTrail,另外给这个空对象添加 WeaponTrail.cs 对象,设置好相关属性,如图: 下面的代码是修改另一篇文章的 TrailsBladeMaster.cs 类,新的代码如下: 复制代码代码如下: using UnityE using System.C using System.Collections.G [AddComponentMenu(&PocketRPG/Blade Master&)] public class TrailsBladeMaster : MonoBehaviour { /// summary /// 拖尾效果 /// /summary public WeaponTrail weaponS public AnimationClip idleC public AnimationClip runC /// summary /// 移动速度 /// /summary public float speed = 20.0f; public Camera mainC private A protected TrailsAnimationController animationC protected CharacterController characterC /// summary /// 运行状态 /// /summary private bool isMoving = /// summary /// 目标位置 /// /summary private Vector3 targetP /// summary /// 移动向量 /// /summary private Vector3 moveD protected void Awake () { this.animation = this.GetComponent Animation this.animationController = this.GetComponent TrailsAnimationController this.characterController = this.GetComponent CharacterController this.animation.CrossFade (this.idleClip.name); } protected void Start () { if (this.weaponSwipe != null) this.animationController.AddTrail (this.weaponSwipe); } protected void Update () { if (!this.isMoving Input.GetMouseButtonDown(0)) { this.targetPosition = this.GetWorldPosition(); if(this.targetPosition != Vector3.zero) { this.isMoving = this.moveDirection = (this.targetPosition - this.transform.position).normalized * this. this.transform.rotation = Quaternion.LookRotation(new Vector3(this.moveDirection.x, 0f, this.moveDirection.z)); this.animation.CrossFade(this.runClip.name); if(this.weaponSwipe != null) this.weaponSwipe.StartTrail(1f, 0f); } } if (this.isMoving) { if(!this.IsArrivePosition()) { this.characterController.Move(this.moveDirection * Time.deltaTime); } else { this.animation.CrossFade(this.idleClip.name); if(this.weaponSwipe != null) this.weaponSwipe.ClearTrail(); this.transform.position = this.targetP this.isMoving = } } } /// summary /// 验证是否到达目标地点 /// /summary /// returns c true /c if this instanc otherwise, c false /c . /returns private bool IsArrivePosition() { Vector3 currentDirection = (this.targetPosition - this.transform.position). if (this.CalculateNormalized (currentDirection) == this.CalculateNormalized (this.moveDirection) * -1) { } } /// summary /// 规范化比较向量 /// /summary /// returns The normalized. /returns /// param name=&direction& Direction. /param private Vector3 CalculateNormalized(Vector3 direction) { Vector3 value = Vector3. value.x = direction.x 0 ? 1 : -1; value.z = direction.z 0 ? 1 : -1; } /// summary /// 获取世界位置 /// /summary /// returns The world position. /returns private Vector3 GetWorldPosition() { Ray ray = this.mainCamera.ScreenPointToRay(Input.mousePosition); RaycastHit raycastH if(Physics.Raycast(ray, out raycastHit)) { if(raycastHit.collider.gameObject.name == &Terrain&) { return raycastHit. } } return Vector3. } } 最后给角色对象挂载 TrailsAnimationController.cs 组件以及 TrailsBladeMaster.cs 组件,同时还需要添加一个角色控制器(CharacterController),因为我们用这个来驱动角色移动,如图: 最后运行可以查看效果,点击地形,角色向目标点移动,并带有拖尾效果。 小编推荐:
上一篇 &:
下一篇 &:
文章链接:///tutorials/26445.html
(转载时请注明本文出处及文章链接)想要实现一个类似TrailRender 的拖尾效果【unity3d吧】_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:76,639贴子:
想要实现一个类似TrailRender 的拖尾效果收藏
大家好 我有一个功能 想要实现类似TrailRender的拖尾功能
像贪吃蛇一样 随着鼠标的移动 蛇头增加 蛇尾减少 鼠标停止后 尾部一点点消失 最后线条全部消失现在的思路做法是 将鼠标移动的触摸点保存下来 根据时间和手指的位置 不停的增加 减少触摸点
然后根据每个触摸点计算一下路径影响的范围 控制一张图片的相应位置的像素颜色
最后在生成一张图片负责给shader 进行贴图显示 不知道我说的明不明白
达内unity3d培训全程&实战教学&,unity3d金牌讲师授课.免费unity3d课程试听中!到达内unity3d学院学习unity3d,只需4个月速成unity3d游戏工程师.
但是现在的问题是 由于每次都在update中进行这种位置判断 计算量有些大 在移动端就会非常卡?不知道又没人能提供一个新的思路
登录百度帐号推荐应用&鍔犺浇涓