C# Unity3D-向点旋转对象并滚动
我有一个游戏对象,它可以一直向前移动,并可以使用此功能向左、向右、上下转动:C# Unity3D-向点旋转对象并滚动,c#,unity3d,C#,Unity3d,我有一个游戏对象,它可以一直向前移动,并可以使用此功能向左、向右、上下转动: void moveTowardsPoint(Vector3 targetPoint) { //forward movement var movementSpeed = Time.deltaTime * speed; transform.position += transform.forward * movementSpeed; //rotation Vector3 dir =
void moveTowardsPoint(Vector3 targetPoint)
{
//forward movement
var movementSpeed = Time.deltaTime * speed;
transform.position += transform.forward * movementSpeed;
//rotation
Vector3 dir = targetPoint - transform.position;
Quaternion targetRotation = Quaternion.LookRotation(dir);
var turnSpeed = Time.deltaTime * 2f;
transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, turnSpeed);
}
我想让这个物体滚动,与它向左或向右旋转的程度成比例。对于20°转弯,我也希望滚动20°(相对于我的星形缠绕的角度)
如果我能设定一个滚动极限,它会旋转30°,然后滚动15°,那就更好了
以下是此行为的自上而下视图:
你能想象一下这种滚动行为是如何工作的吗?对于这两种情况,这里有一张我试图让它看起来像什么的图片。把它想象成一架飞机是如何旋转的,你能想象一下这种滚动行为是如何工作的吗?对于这两种情况,这里有一张我试图让它看起来像什么的图片。想象一下飞机是如何转弯的