[英]Unity RigidBody2D.AddForce() method stopped player movement, stuck without move
[英]My character's horizontal movement is stopping me from using rigidBody2D.AddForce(Vector2.right) or any horizontal axis
我一直尝试向左或向右添加力,但没有任何反应。 这发生在我之前的另一场比赛中。 我才明白那是什么
rb.velocity = new Vector2(speed * moveX * Time.deltaTime, rb.velocity.y);
在这里,如果我不移动,我将速度设置为 0(moveX 是Input.GetAxisRaw("Horizontal")
)如何水平添加力,同时不必禁用我的正常移动? 我知道我可以使用 transform.Translate,但我现在更喜欢使用 rb.velocity。
使用 add force function,链接到下面的统一文档。
https://docs.unity3d.com/ScriptReference/Rigidbody2D.AddForce.html
我已经遇到过好几次了,但是
如果您使用的是AddForce
,您可以做的是确保为其添加大量的速度值
rb.AddForce(inputMove.x * speed);
如果您正在使用Time.deltatime
或根本不使用时间...类似:
rb.AddForce(inputMove.x * Time.deltatime * speed);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.