我想旋转一个瓶子(我正在计算鼠标的第一个pos和结束pos)并根据'swipe'长度/时间对它施加力。初次刷卡后,瓶子应该根据刷卡的力量继续旋转,然后在几秒钟后停止。旋转一个瓶子Unity3D
我希望你能帮助我。谢谢!
这是我试图这样做,但它不能很好地工作:
public Rigidbody bottle;
bool isSwiping;
Touch thisTouch;
Vector2 origPos;
Vector2 endPos;
float touchSpeed;
Vector3 Torque;
float timeStart; float timeEnd;
void OnMouseDown()
{
timeStart = Time.time;
origPos = Input.mousePosition;
}
void OnMouseDrag()
{
isSwiping = true;
}
void OnMouseUp()
{
if (isSwiping)
{
timeEnd = Time.time;
endPos = Input.mousePosition;
Vector2 deltaPosition = endPos - origPos;
touchSpeed = deltaPosition.magnitude/(timeEnd-timeStart);
Torque = new Vector3(touchSpeed * 500f, 0, 0);
}
}
void Update()
{
}
void FixedUpdate()
{
if (isSwiping) bottle.AddRelativeTorque(Torque);
}
你能在什么复杂的“没有按在这种情况下工作不好“?请根据需要使用附加信息和视觉辅助工具编辑您的问题。 – Serlite
可能对于滑动你尝试使用Input.GetAxis(“Horizonal”)检测速度变化X坐标鼠标和Input.GetAxis(“垂直”)的Y? –
@Serlite我的意思是它不旋转,什么都不做。 –