[英]How to make a smooth mouse movement in unity?
我正在为智能手机编写二维统一游戏。 玩家用鼠标左右摆动。 但鼠标移动并不顺畅。 也就是说,当我单击鼠标按钮时,玩家的转弯很尖锐。 如何使运动平稳? 请帮忙。 我的代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class qwe : MonoBehaviour
{
private float angle0ffset;
public float direction = 1f; // initial direction
public float speed = 20f; // speed of rotation
void Update ()
{
if (Input.GetMouseButtonDown(0))
{
float angle = transform.eulerAngles.z;
if (angle > 180f) angle -= 360f;
if ((angle < -10f) || (angle > 10f)) direction *= -1f; // reverse direction (toggles between 1 & -1)
transform.Rotate (0, 0, speed * direction * Time.deltaTime);
}
}
}
我认为您需要使用 Quaternion.Slerp()。 我在 Unity 论坛中找到了这个人,他提出了一个非常相似的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.