Created
June 12, 2021 07:09
-
-
Save flushpot1125/819906d91712548d46089272d453b083 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Mesh,PhysicsImpostor } from "@babylonjs/core"; | |
import { fromScene} from "../tools"; | |
export default class block extends Mesh { | |
@fromScene("ball") | |
_ball :Mesh;//1つ上の行の"@fromScene"の引数が、Graph View上のオブジェクト名 (この場合は"ball"というオブジェクトがGraph Viewに存在する)。そのオブジェクトを_ballに対応させる | |
//補足 Graph Viewは、UnityのHierarchy Viewと同等 | |
//block生成時に1度だけ呼ばれる | |
public onStart(): void { | |
//ここでブロックに物理エンジンをつけている。mass:0にしないと、ブロックが浮いてしまう。friction(摩擦係数):0, restitution(反発係数):1により弾性衝突を実現 | |
this.physicsImpostor = new PhysicsImpostor(this, PhysicsImpostor.BoxImpostor, { mass: 0, friction: 0, restitution: 1.0 }); | |
} | |
//毎フレームごとに呼ばれる | |
public onUpdate(): void { | |
//intersectsMeshを使うと、引数のオブジェクトと衝突したら、という処理が作れる | |
if ((this.intersectsMesh(this._ball)) && this.callFlag== false){ | |
this.callFlag=true; | |
console.log("collisioned!"); | |
// this.dispose();//dispose = Unityのdestroyと同じ。ここで呼べば、ボールが衝突した瞬間に消えるので、ボールが貫通してしまう | |
this.blockDispose(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment