Im making a game in canvas and I have included a library to deal with collision for me.
(我在画布上制作游戏,并且提供了一个库来为我处理碰撞。)
The collision is working perfectly, but I am not really sure how to "freeze" the player in place and not allow movement in that direction after colliding. (碰撞工作正常,但是我不确定如何将玩家“冻结”到位,并且在碰撞后不允许沿该方向移动。)
Can anyone help me out ? (谁能帮我吗 ?)
What I tried :
(我试过了)
moveRight() {
this.pp.x = this.position.x;
this.position.x += 20;
}
moveLeft() {
this.pp.x = this.position.x;
this.position.x -= 20;
}
moveUp() {
this.pp.y = this.position.y;
this.position.y += 20;
}
moveDown() {
this.pp.y = this.position.y;
this.position.y -= 20;
}
I tried keeping track of "previous position" and set it to that on collision, but it's behaving really strange, doesn't really work.
(我尝试跟踪“先前位置”并将其设置为发生碰撞时的位置,但是它的行为确实很奇怪,实际上并不起作用。)
Ideally, I would like to make a stop() function in my player class that I would call upon player colliding with the world.
(理想情况下,我想在我的玩家类中创建一个stop()函数,呼吁玩家与世界碰撞。)
Thanks so much, any help is greatly appreciated !
(非常感谢,非常感谢您的帮助!)
! (!)
! (!)
ask by sillenius translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…