Created
December 9, 2022 02:16
-
-
Save flushpot1125/9c47dac7903a772e05f22c7ce469a031 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
var map ={}; //object for multiple key presses | |
//キー入力を受け付ける宣言 | |
//キー入力があるたびに、map変数の値がセットされる | |
scene.actionManager = new BABYLON.ActionManager(scene); | |
scene.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnKeyDownTrigger, function (evt) { | |
map[evt.sourceEvent.key] = evt.sourceEvent.type == "keydown"; | |
})); | |
scene.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnKeyUpTrigger, function (evt) { | |
map[evt.sourceEvent.key] = evt.sourceEvent.type == "keydown"; | |
})); | |
var distance = 0.01; | |
//繰り返し呼ばれる | |
scene.registerAfterRender(function() { | |
//"a"または"A"を押し続けている間、if文を実行 | |
if((map["a"] || map["A"])){ | |
sphere.translate(BABYLON.Axis.X, -distance, BABYLON.Space.LOCAL); | |
} | |
//"d"または"D"を押し続けている間、if文を実行 | |
if((map["d"] || map["D"])){ | |
sphere.translate(BABYLON.Axis.X, distance, BABYLON.Space.LOCAL); | |
} | |
//"w"または"W"を押し続けている間、if文を実行 | |
if((map["w"] || map["W"])){ | |
sphere.translate(BABYLON.Axis.Z, distance, BABYLON.Space.LOCAL); | |
} | |
//"s"または"S"を押し続けている間、if文を実行 | |
if((map["s"] || map["S"])){ | |
sphere.translate(BABYLON.Axis.Z, -distance, BABYLON.Space.LOCAL); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment