使用Vector3.slerp [英] Using Vector3.slerp

查看:162
本文介绍了使用Vector3.slerp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道我是否在正确使用vector3.slerp,因为我遇到了一些问题.

I just want to know if I'm using vector3.slerp correctly as I have some issues.

我在场景中设置了一个多维数据集,我希望它从当前位置平稳地移动到程序所传递的位置.在尝试使用slerp之前,我只是将多维数据集从当前点移动到了这样的新点(就像我说的,数学都可以正常工作):

I have set up a cube in a scene and I want it move smoothly from its current position to one being passed into by the program. Before I was trying to use the slerp I simply had my cube moving from its current point to its new point like this (as I said, the math all works):

cubeFour.transform.localPosition = new Vector3((B2*C1 - B1*C2)/delta,0,(A1*C2 - A2*C1)/delta);  

但是当我将其放入电话时,我的多维数据集不再出现在屏幕上.这就是我的称呼方式:

But when I put it in a slerp call, my cube is no longer on the screen. This is how I'm calling it:

Vector3 targetPosition = new Vector3(lerpX, lerpY, lerpZ);

cubeFour.transform.localPosition = Vector3.Slerp(cubeFour.transform.localPosition, targetPosition, Time.deltaTime);

LerpX,LerpY& LerpZ是我设置为包含X,Y和A的局部变量.我第一次尝试创建的第一个Vector3的Z.

LerpX, LerpY & LerpZ are local variables I've set to contain the X, Y & Z of the first Vector3 I created in my first attempt.

我是否正确设置了皮带,或者在某处做了a子呢?

Have I set up the slerp correctly or have I made a kerfuffle somewhere?

推荐答案

最适合指示路线, Lerp 最好职位.您可能应该使用Lerp.而且 Time.deltaTime 几乎肯定是t的错误选择.您应该给它一个数字,该数字在您希望多维数据集移动的时间内从0移到1,例如

Slerp is best for directions, Lerp is best for positions. You should probably be using Lerp. And Time.deltaTime is almost certainly the wrong choice for t. You should be giving it a number that moves from 0 to 1 over the time that you want the cube to move, e.g.

float moveTimeInSeconds = 2;
cubeFour.transform.localPosition = Vector3.Lerp(cubeStartingPosition, targetPosition, (Time.time - startTime) / moveTimeInSeconds);

或者如果更合理的定义是使用 MoveTowards 的运动速度,而不管起点和终点如何,而不是通过起点和终点的位置和时间来移动.

Or use MoveTowards if it makes more sense to define the speed of motion, and to move towards a target regardless of a starting point, instead of via starting and ending positions and times.

float step = speed * Time.deltaTime;
cubeFour.transform.localPosition = Vector3.MoveTowards(cubeFour.transform.localPosition, targetPosition, step);

这篇关于使用Vector3.slerp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆