实现坠落伤害 phaser.js

huangapple go评论57阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年2月23日 22:04:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/75545871.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定