using UnityEngine; /// <summary> /// 闪现技能 /// </summary> public class flashMove : MonoBehaviour { //放闪现的按键 public KeyCode keyCode= KeyCode.A; //闪现的距离 public float moveDistance =9.7f; // Update is called once per frame void Update () { release(); } void release() { if(Input.GetKeyDown(keyCode)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit = new RaycastHit(); if (Physics.Raycast(ray, out hit)) { if (hit.collider.tag == "Terrain") { Vector3 hitPos = hit.point; Vector3 playerPos = transform.position; //向量减法 和y无关,所以同步一下高度 playerPos.y = hitPos.y; //向量减法,得到一个向量,包含方向和距离 Vector3 dir = (hitPos - playerPos); //归一化 去除距离 ,只要方向,如果不去除距离 ,那么角色闪到鼠标点击的位置 dir = dir.normalized; //目标点 点b =点a + 方向 * 距离; Vector3 targetPos = transform.position + dir * moveDistance; //计算目标点 的地面实际高度 targetPos.y = hit.point.y; transform.position = targetPos; } } } } }
Unity3d 实现 闪现 技能
猜你喜欢
转载自blog.csdn.net/u013628121/article/details/79591101
今日推荐
周排行