实现坠落伤害 phaser.js

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

Implementing fall damage phaser.js

问题

以下是翻译好的代码部分:

  1. console.log(this.player.body.velocity.y) // works
  2. this.fallDmgAmt = 0;
  3. if(this.player.body.onFloor()==false && this.player.velocity.y >= 300){ // doesn't work
  4. console.log("falling")
  5. }
英文:

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

  1. console.log(this.player.body.velocity.y) // works
  2. this.fallDmgAmt = 0;
  3. if(this.player.body.onFloor()==false && this.player.velocity.y >= 300){ // doesn't work
  4. console.log("falling")
  5. }

the first velocity works but the second doesn't, any explanations?

答案1

得分: 4

将if语句更改为以下内容:

  1. if (this.player.body.onFloor() == false && this.player.body.velocity.y >= 300) {
  2. console.log("falling");
  3. }

你使用的是 this.player.velocity.y 而不是 this.player.body.velocity.y

英文:

change the if statement to the following:

  1. if (this.player.body.onFloor() == false && this.player.body.velocity.y >= 300) {
  2. console.log("falling");
  3. }

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:

确定