【问题标题】:Unity rotation objectunity旋转对象
【发布时间】:2016-01-11 00:15:40
【问题描述】:

我有一个关于旋转的问题,如果你看到这个 gif:https://i.gyazo.com/a1fbdbf4c125227e0bbfeda552c2981f.gif

你会注意到,当他看起来像“钻石”时,他下落的速度非常慢,有什么提示可以解决这个问题吗?

我的代码:

void FixedUpdate() {

    grounded1 = Physics2D.OverlapCircle(groundCheck1.position, 0.15f, groundLayer);
    grounded2 = Physics2D.OverlapCircle(groundCheck2.position, 0.15f, groundLayer);
    grounded3 = Physics2D.OverlapCircle(groundCheck3.position, 0.15f, groundLayer);
    grounded4 = Physics2D.OverlapCircle(groundCheck4.position, 0.15f, groundLayer);

    float movex = Input.GetAxisRaw("Horizontal");
    GetComponent<Rigidbody2D>().velocity = new Vector2(movex * speed, GetComponent<Rigidbody2D>().velocity.y);

    if (Input.GetKey(KeyCode.UpArrow) && (grounded1 == true)) {
        GetComponent<Rigidbody2D>().AddForce(new Vector2(0, 15), ForceMode2D.Impulse);
    } else if (Input.GetKey(KeyCode.UpArrow) && (grounded2 == true)) {
        GetComponent<Rigidbody2D>().AddForce(new Vector2(0, 15), ForceMode2D.Impulse);
    } else if (Input.GetKey(KeyCode.UpArrow) && (grounded3 == true)) {
        GetComponent<Rigidbody2D>().AddForce(new Vector2(0, 15), ForceMode2D.Impulse);
    } else if (Input.GetKey(KeyCode.UpArrow) && (grounded4 == true)) {
        GetComponent<Rigidbody2D>().AddForce(new Vector2(0, 15), ForceMode2D.Impulse);
    }


    if ((Input.GetKey(KeyCode.LeftShift)) && (Input.GetKey(KeyCode.RightArrow))) {
        transform.Rotate(Vector3.forward * -5);
    }

    if ((Input.GetKey(KeyCode.LeftShift)) && (Input.GetKey(KeyCode.LeftArrow))) {
        transform.Rotate(Vector3.forward * 5);
    }
}

谢谢。

【问题讨论】:

  • Vitor 如果你想包含一张图片,点击你的问题上的编辑...寻找一个使用方便的“图片”按钮,你可以在问题中显示图片

标签: c# unity3d


【解决方案1】:

为什么不使用角速度而不是 transform.Rotate ?

GetComponent<Rigidbody2D>().angularVelocity

您正在使用物理进行跳跃但使用变换函数进行旋转,最好在同一个范例中进行。

【讨论】:

  • 太棒了!解决了我的问题,给了我另一个想法,谢谢!
猜你喜欢
  • 1970-01-01
  • 2015-06-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多