我為 2d 角色制作了一個(gè)控制器,我修復(fù)了玩家在墻上抖動(dòng)的問題,但我無法修復(fù)玩家在地面上抖動(dòng)的問題。從多個(gè)教程和調(diào)整內(nèi)容中獲取了此代碼。如果您有任何提示,我們將不勝感激,我是這方面的新手,正在開發(fā)我的第一個(gè)游戲(因?yàn)槲曳胖昧颂啻a而不得不閑逛),謝謝。{ public float speed, height; Rigidbody2D rb; private bool horizontalRight = false; private bool horizontalLeft = false; private bool verticalMove = false; private void Start() { rb = GetComponent<Rigidbody2D>(); } void Update() { if (Input.GetAxisRaw("Horizontal") > 0) { horizontalRight = true; } else if (Input.GetAxisRaw("Horizontal") < 0) { horizontalLeft = true; } if (Input.GetButton("Jump") && rb.velocity.y == 0) { verticalMove = true; } } private void FixedUpdate() { if (horizontalRight == true) { transform.Translate(Vector2.right * Time.deltaTime * speed); horizontalRight = false; } else if (horizontalLeft == true) { transform.Translate(Vector2.left * Time.deltaTime * speed); horizontalLeft = false; } if (verticalMove == true) { rb.velocity = new Vector2(0, height); verticalMove = false; } }}
2 回答

12345678_0001
TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超5個(gè)贊
激活剛體上的連續(xù)碰撞檢測,只要它們通過速度移動(dòng),它就會(huì)阻止它們逐步穿過物體。

斯蒂芬大帝
TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超8個(gè)贊
典型的統(tǒng)一跳躍如下所示:
void Jump()
{
if (_isGrounded == true)
{
rb.AddForce(Vector2.up * _jumpSpeed);
_isGrounded = false;
}
}
并且在碰撞事件中
void OnCollisionEnter (Collision hit)
{
_isGrounded = true;
}
這會(huì)限制你何時(shí)可以使用跳躍。
- 2 回答
- 0 關(guān)注
- 163 瀏覽
添加回答
舉報(bào)
0/150
提交
取消