【问题标题】:Rotate object using Sin and Cos using Time.deltaTime使用 Time.deltaTime 使用 Sin 和 Cos 旋转对象
【发布时间】:2019-02-09 22:37:24
【问题描述】:

我想知道如何使用 time.deltaTime 来移动一个对象,而它应该只能在一个圆圈上移动。

在这种情况下,我正在处理一个围绕玩家旋转的相机。

    _GoalX += Input.GetAxis("Mouse X");

    float y = _PlayerHeight;
    float x = Mathf.Cos(_GoalX);
    float z = Mathf.Sin(_GoalX);
    transform.localPosition = new Vector3(x, y, z);

相机不应立即放置在目标位置,而是随着时间的推移,在玩家周围的圆圈上移动。

我不能使用 Vector3.Lerp(startvector,targetvector) 因为那样相机可能会进入播放器。

【问题讨论】:

  • 你将不得不做类似position = (player.x + distance * cos(phi), player.y + heightOfCameraAbovePlayer, player.z + distance * sin(phi)).(伪代码)

标签: c# unity3d math


【解决方案1】:

在更新中你可以这样做:

void update(){
angle += RotateSpeed * Time.deltaTime;
Vector3 offset = new Vector3(Mathf.Sin(_angle)* xRadius, _PlayerHeight, Mathf.Cos(_angle)* zRadius);
transform.position = _centre + offset;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多