010203040506070809101112131415161718192021 | [/font][/size][/align][align=left][size=4][font=宋体] //在日出和日落之间动画弧线 using UnityEngine; using System.Collections; public class example : MonoBehaviour { public Transform sunrise; public Transform sunset; void Update() { //弧线的中心 Vector3 center = sunrise.position + sunset.position * 0.5f; //向下移动中心,垂直于弧线 center -= new Vector3(0, 1, 0); //相对于中心在弧线上插值 Vector3 riseRelCenter = sunrise.position - center; Vector3 setRelCenter = sunset.position - center; transform.position = Vector3.Slerp(riseRelCenter, setRelCenter, Time.time); transform.position += center; } } |
1234 | [/font][/align][align=left][font=宋体] for ( int i = 1; i < 10; ++i) { Vector3 drawVec = Vector3.Slerp(a, b, 0.1f * i); Debug.DrawLine(Vector3.zero, drawVec, Color.yellow); } |
0102030405060708091011 | [/font][/align][align=left][font=宋体] //弧线的中心 Vector3 center = (a + b) * 0.5f; //我们把中心点向下移动中心,垂直于弧线 center -= new Vector3(0, 0.5f, 0); // 求出新的中心点到向量a和向量b的 Vector3 vecA = a - center; Vector3 vecB = b - center; for ( int i = 0; i <= 10; ++i) { Vector3 drawVec = Vector3.Slerp(vecA, vecB, 0.1f * i); Debug.DrawLine(center, drawVec, Color.yellow); } |
drawVec += center; |
1 | Vector3 centorPRoject = Vector3.Project(centor, mStart - mEnd); // 中心点在两点之间的投影 centor = Vector3.MoveTowards(centor, centorProject, 1f); // 沿着投影方向移动移动距离(距离越大弧度越小) |
0102030405060708091011121314151617181920 | [/font][/align][align=left][font=宋体] //在日出和日落之间动画弧线 using UnityEngine; using System.Collections; public class example : MonoBehaviour { public Transform sunrise; public Transform sunset; void Update() { //弧线的中心 Vector3 center = sunrise.position + sunset.position * 0.5f; Vector3 centorProject = Vector3.Project(centor, sunrise.position - sunset.position); // 中心点在两点之间的投影 centor = Vector3.MoveTowards(centor, centorProject, 1f); // 沿着投影方向移动移动距离(距离越大弧度越小) //相对于中心在弧线上插值 Vector3 riseRelCenter = sunrise.position - center; Vector3 setRelCenter = sunset.position - center; transform.position = Vector3.Slerp(riseRelCenter, setRelCenter, Time.time); transform.position += center; } } |
centor = Vector3.MoveTowards(centor, centorProject, 1f); // 沿着投影方向移动移动距离(距离越大弧度越小) |
0102030405060708091011121314151617181920212223242526272829 | [/size][/font][/align][align=left][font=宋体][size=14.0pt] private Vector3 mStart = new Vector3(2, 4, -1); private Vector3 mEnd = new Vector3(-1, 1, 2); // Update is called once per frame private void Update() { Debug.DrawLine( new Vector3(-100, 0, 0), new Vector3(100, 0, 0), Color.green); Debug.DrawLine( new Vector3(0, -100, 0), new Vector3(0, 100, 0), Color.green); Debug.DrawLine(Vector3.zero, mStart, Color.red); Debug.DrawLine(Vector3.zero, mEnd, Color.red); Debug.DrawLine(mStart, mEnd, Color.red); Vector3 centor = (mStart + mEnd) * 0.5f; Vector3 centorProject = Vector3.Project(centor, mStart - mEnd); // 中心点在两点之间的投影 centor = Vector3.MoveTowards(centor, centorProject, 1f); // 沿着投影方向移动移动距离(距离越大弧度越小) Debug.DrawLine(centor, mStart, Color.blue); Debug.DrawLine(centor, mEnd, Color.blue); Debug.Log( string .Format( "{0} : {1}" , Vector3.Distance(centor, mStart), Vector3.Distance(centor, mEnd))); for ( int i = 1; i < 10; ++i) { Vector3 drawVec = Vector3.Slerp(mEnd - centor, mStart - centor, 0.1f * i); drawVec += centor; Debug.DrawLine(centor, drawVec, 5 == i ? Color.blue : Color.yellow); } } |
新闻热点
疑难解答