这是使用lerp和mouseDrag事件移动我的对象的代码,但它不能很顺利地工作。
//Camera Point smooth movment
if (mouseWorking)
{
if (Physics.Raycast(ray, out hit, Camera.main.farClipPlane)) //,LayerMask.NameToLayer("Gola")))
{
if (hit.transform.gameObject.name == "CameraElasticPoint")
{
return;
}
else
{
//working
transform.position = Vector3.Lerp(transform.position, new Vector3(hit.point.x, hit.point.y + 1, hit.point.z), Time.deltaTime * 3); //0.5000001f
//StartCoroutine(SmoothMove());
hitPoint = Input.mousePosition;
}
}
}
答案 0 :(得分:-1)
您可能会发现Vector's Lerp更平滑。
public class ExampleClass : MonoBehaviour {
public Transform startMarker;
public Transform endMarker;
public float speed = 1.0F;
private float startTime;
private float journeyLength;
void Start() {
startTime = Time.time;
journeyLength = Vector3.Distance(startMarker.position, endMarker.position);
}
void Update() {
float distCovered = (Time.time - startTime) * speed;
float fracJourney = distCovered / journeyLength;
transform.position = Vector3.Lerp(startMarker.position, endMarker.position, fracJourney);
}
}