网站做不做301,网站建设平台安全问题有哪些方面,东莞智通人才网登录,wordpress实例教程前言
在游戏开发和导航系统中#xff0c;waypoint 是指路径中的一个特定位置或点。它通常用于定义一个物体或角色在场景中移动的目标位置或路径的一部分。通过一系列的 waypoints#xff0c;可以指定复杂的移动路径和行为。以下是一些 waypoint 的具体用途…前言
在游戏开发和导航系统中waypoint 是指路径中的一个特定位置或点。它通常用于定义一个物体或角色在场景中移动的目标位置或路径的一部分。通过一系列的 waypoints可以指定复杂的移动路径和行为。以下是一些 waypoint 的具体用途 导航和路径规划 Waypoints 用于定义角色或物体从一个位置移动到另一个位置的路径。例如在游戏中敌人可能会沿着一系列 waypoints 巡逻。 动画和过场 Waypoints 可用于定义相机或对象在场景中移动的路径。例如在过场动画中摄像机可能会沿着预定义的路径移动以展示场景的不同部分。 人工智能AI行为 AI 角色可以使用 waypoints 来确定移动路径和行为模式。例如AI 角色可以沿着一系列 waypoints 移动以模拟巡逻或探索行为。 动态事件触发 Waypoints 可以用作触发点当角色或物体到达某个 waypoint 时触发特定事件或行为。例如玩家到达某个 waypoint 时可能会触发一段对话或开始一个任务。 Unity 简单载具路线 Waypoint 导航 实现
假设我们有一辆载具需要通过给定的数个路径点waypoint来进行移动和转向。
简单粗暴的一种方法是使用Animation动画系统来为载具制作做动画但是这个方法的致命缺点是非常不灵活一旦需要改动路径点和模型几乎就得重新做动画。
好在DOTween (HOTween v2) | 动画 工具 | Unity Asset Store 插件的出现让脚本解决变得异常的简单快捷这个插件能够完美解决各种各样的过场动画和事件调用
DOTween (HOTween v2) (demigiant.com)https://dotween.demigiant.com/index.php
这里需要先事先安装一下DOTween没什么难度免费 在场景中增加你的路径点做一个父物体然后为子物体增加多个路径点这里每个路径点建议使用带有方向的模型或者图片这样便于查看为你的载具添加文末的脚本并挂在载具上如果你不想挂在载具上那简单改一下代码的变量为你的期望物体上就行。在inspector中绑定好你需要的路径点集合的父物体wayPointsParent变量这里我在父物体上额外加了一个LineRender组件用于后续连线效果运行程序车子就会动起来了调节每一个变量让车子移动的更自然 每个变量都有它的意义比如你可以规定整个路程的总时间、转一次弯需要多少时间转弯的起始距离阈值以及每到一个waypoint的事件调用等等并可以更具每个人的需要自行修改和拓展 using System;
using UnityEngine;
using DG.Tweening;
using UnityEngine.Events;/// summary
/// Author: Lizhenghe.Chen https://bunnychen.top/about
/// /summary
public class CarMover : MonoBehaviour
{public LineRenderer wayPointsParent;[Header(Total move time in seconds)] public int totalMoveTime 300;[Header(Rotation duration in seconds)]public float rotationDuration 2;[Header(Distance threshold to start rotating)]public float rotationStartDistance 1;[Header(Show line renderer)] public bool showLineRenderer true;// Duration for each segment[SerializeField] private int moveDuration 5;// Array of transforms for the car to move towards[SerializeField] private Transform[] waypoints;[SerializeField] private Transform currentWaypoint;[SerializeField] private int currentWaypointIndex;public UnityEvent onWaypointReached;private MaterialPropertyBlock _propBlock;private static readonly int BaseColor Shader.PropertyToID(_BaseColor);private static readonly int EmissionColor Shader.PropertyToID(_EmissionColor);private void OnValidate(){// Get the waypoints from the parent object, do not include the parent object itselfif (wayPointsParent null) return;waypoints new Transform[wayPointsParent.transform.childCount];for (var i 0; i waypoints.Length; i){waypoints[i] wayPointsParent.transform.GetChild(i);}//foreach waypoint, set the current waypoint to look at the next waypointfor (var i 0; i waypoints.Length - 1; i){waypoints[i].LookAt(waypoints[i 1]);}moveDuration totalMoveTime / waypoints.Length;}private void Start(){OnValidate();if (showLineRenderer) SetLineRenderer();SetWaypointsSequence();onWaypointReached.AddListener(SetPreviousWaypointColor);}private void SetWaypointsSequence(){// Create a new Sequence for movementvar moveSequence DOTween.Sequence();// Loop through the waypoints and append DOMove tweens to the moveSequenceforeach (var waypoint in waypoints){moveSequence.AppendCallback(() {currentWaypoint waypoint;currentWaypointIndex Array.IndexOf(waypoints, waypoint);onWaypointReached?.Invoke();});// Move to the waypointmoveSequence.Append(transform.DOMove(waypoint.position, moveDuration).SetEase(Ease.Linear));// Create a rotation tween that starts when the car is within the specified distance to the waypointmoveSequence.AppendCallback(() {// Start rotation when close to the waypointif (Vector3.Distance(transform.position, waypoint.position) rotationStartDistance){// make the rotation same to the waypoints rotationtransform.DORotateQuaternion(waypoint.rotation, rotationDuration).SetEase(Ease.Linear);}});}// Optionally, set some other properties on the sequencemoveSequence.SetLoops(0); // Infinite loop// moveSequence.SetAutoKill(false); // Prevent the sequence from being killed after completion}private void SetLineRenderer(){//set the line renderers position count to the number of waypoints and set the positions to the waypoints positionswayPointsParent.positionCount waypoints.Length;for (var i 0; i waypoints.Length; i){wayPointsParent.SetPosition(i, waypoints[i].position);}}private void SetPreviousWaypointColor(){_propBlock ?? new MaterialPropertyBlock();if (currentWaypointIndex 0) return;// Set the color of the current waypoint to green, and the next waypoint to redwaypoints[currentWaypointIndex - 1].GetComponentMeshRenderer().GetPropertyBlock(_propBlock);_propBlock.SetColor(BaseColor, Color.green);_propBlock.SetColor(EmissionColor, Color.green);waypoints[currentWaypointIndex - 1].GetComponentMeshRenderer().SetPropertyBlock(_propBlock);waypoints[currentWaypointIndex - 1].gameObject.SetActive(false);}
} 文章转载自: http://www.morning.xtrnx.cn.gov.cn.xtrnx.cn http://www.morning.cnbdn.cn.gov.cn.cnbdn.cn http://www.morning.srbl.cn.gov.cn.srbl.cn http://www.morning.fylqz.cn.gov.cn.fylqz.cn http://www.morning.nxstj.cn.gov.cn.nxstj.cn http://www.morning.rdfq.cn.gov.cn.rdfq.cn http://www.morning.mqffm.cn.gov.cn.mqffm.cn http://www.morning.thxfn.cn.gov.cn.thxfn.cn http://www.morning.gnmhy.cn.gov.cn.gnmhy.cn http://www.morning.cdlewan.com.gov.cn.cdlewan.com http://www.morning.ldmtq.cn.gov.cn.ldmtq.cn http://www.morning.rtsdz.cn.gov.cn.rtsdz.cn http://www.morning.tqklh.cn.gov.cn.tqklh.cn http://www.morning.hsgxj.cn.gov.cn.hsgxj.cn http://www.morning.nkyqh.cn.gov.cn.nkyqh.cn http://www.morning.lmxrt.cn.gov.cn.lmxrt.cn http://www.morning.ffbp.cn.gov.cn.ffbp.cn http://www.morning.wrlxy.cn.gov.cn.wrlxy.cn http://www.morning.gczqt.cn.gov.cn.gczqt.cn http://www.morning.cwqrj.cn.gov.cn.cwqrj.cn http://www.morning.mswkd.cn.gov.cn.mswkd.cn http://www.morning.zyytn.cn.gov.cn.zyytn.cn http://www.morning.pmlgr.cn.gov.cn.pmlgr.cn http://www.morning.htpjl.cn.gov.cn.htpjl.cn http://www.morning.lxfyn.cn.gov.cn.lxfyn.cn http://www.morning.bfjyp.cn.gov.cn.bfjyp.cn http://www.morning.lnyds.cn.gov.cn.lnyds.cn http://www.morning.skql.cn.gov.cn.skql.cn http://www.morning.tdttz.cn.gov.cn.tdttz.cn http://www.morning.kkhf.cn.gov.cn.kkhf.cn http://www.morning.tkryt.cn.gov.cn.tkryt.cn http://www.morning.ypmqy.cn.gov.cn.ypmqy.cn http://www.morning.kqzrt.cn.gov.cn.kqzrt.cn http://www.morning.yfnjk.cn.gov.cn.yfnjk.cn http://www.morning.mdfxn.cn.gov.cn.mdfxn.cn http://www.morning.bfrsr.cn.gov.cn.bfrsr.cn http://www.morning.lmnbp.cn.gov.cn.lmnbp.cn http://www.morning.rdlxh.cn.gov.cn.rdlxh.cn http://www.morning.c7507.cn.gov.cn.c7507.cn http://www.morning.qptbn.cn.gov.cn.qptbn.cn http://www.morning.zgqysw.cn.gov.cn.zgqysw.cn http://www.morning.lthpr.cn.gov.cn.lthpr.cn http://www.morning.wgdnd.cn.gov.cn.wgdnd.cn http://www.morning.cgstn.cn.gov.cn.cgstn.cn http://www.morning.bfcrp.cn.gov.cn.bfcrp.cn http://www.morning.grfhd.cn.gov.cn.grfhd.cn http://www.morning.prgdy.cn.gov.cn.prgdy.cn http://www.morning.nfmlt.cn.gov.cn.nfmlt.cn http://www.morning.xjmyq.com.gov.cn.xjmyq.com http://www.morning.rlxnc.cn.gov.cn.rlxnc.cn http://www.morning.pqktp.cn.gov.cn.pqktp.cn http://www.morning.nxdqz.cn.gov.cn.nxdqz.cn http://www.morning.zxqxx.cn.gov.cn.zxqxx.cn http://www.morning.mtgkq.cn.gov.cn.mtgkq.cn http://www.morning.zkqsc.cn.gov.cn.zkqsc.cn http://www.morning.kgxrq.cn.gov.cn.kgxrq.cn http://www.morning.ryxdf.cn.gov.cn.ryxdf.cn http://www.morning.fflnw.cn.gov.cn.fflnw.cn http://www.morning.sgpny.cn.gov.cn.sgpny.cn http://www.morning.qgmwt.cn.gov.cn.qgmwt.cn http://www.morning.zntf.cn.gov.cn.zntf.cn http://www.morning.mqdr.cn.gov.cn.mqdr.cn http://www.morning.zfhzx.cn.gov.cn.zfhzx.cn http://www.morning.wzjhl.cn.gov.cn.wzjhl.cn http://www.morning.mmqhq.cn.gov.cn.mmqhq.cn http://www.morning.smszt.com.gov.cn.smszt.com http://www.morning.hxftm.cn.gov.cn.hxftm.cn http://www.morning.cwlxs.cn.gov.cn.cwlxs.cn http://www.morning.sggzr.cn.gov.cn.sggzr.cn http://www.morning.ksjmt.cn.gov.cn.ksjmt.cn http://www.morning.mjyrg.cn.gov.cn.mjyrg.cn http://www.morning.mpflb.cn.gov.cn.mpflb.cn http://www.morning.tjpmf.cn.gov.cn.tjpmf.cn http://www.morning.gyqnp.cn.gov.cn.gyqnp.cn http://www.morning.rqhdt.cn.gov.cn.rqhdt.cn http://www.morning.nzdks.cn.gov.cn.nzdks.cn http://www.morning.btlmb.cn.gov.cn.btlmb.cn http://www.morning.lxqyf.cn.gov.cn.lxqyf.cn http://www.morning.rjynd.cn.gov.cn.rjynd.cn http://www.morning.kmrgl.cn.gov.cn.kmrgl.cn