英文:
Implementing fall damage phaser.js
问题
以下是翻译好的代码部分:
console.log(this.player.body.velocity.y) // works
this.fallDmgAmt = 0;
if(this.player.body.onFloor()==false && this.player.velocity.y >= 300){ // doesn't work
console.log("falling")
}
英文:
So i'm trying to make some fall damage, with the implementation of seeing whether the player is on the floor or not, but i'm encountering an issue in my if statement
console.log(this.player.body.velocity.y) // works
this.fallDmgAmt = 0;
if(this.player.body.onFloor()==false && this.player.velocity.y >= 300){ // doesn't work
console.log("falling")
}
the first velocity works but the second doesn't, any explanations?
答案1
得分: 4
将if语句更改为以下内容:
if (this.player.body.onFloor() == false && this.player.body.velocity.y >= 300) {
console.log("falling");
}
你使用的是 this.player.velocity.y
而不是 this.player.body.velocity.y
。
英文:
change the if statement to the following:
if (this.player.body.onFloor() == false && this.player.body.velocity.y >= 300) {
console.log("falling");
}
You are using this.player.velocity.y
instead of this.player.body.velocity.y
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论