I want to change the character displayed by conditional branching in the function executed at setInterval
Please write your question here in detail.
I want to change the characters displayed according to the direction of the camera in the A-frame.
For that purpose, we first tested whether the display could be changed by conditional branching on the console.
"Good morning" is always displayed on the console, and conditional branching is not well done.
No error has occurred.
Applicable source code<! DOCTYPE html>
<html lang = "ja" dir = "ltr">
<head>
<meta charset = "utf-8">
<title>Sample A-frame</title>
<script src = "https://aframe.io/releases/0.7.1/aframe.min.js"></script>
</head>
<body>
</a-cursor>
</a-camera>
</a-scene>
<script type = "text/javascript">
// get a-camera
var camera = document.getElementById ('a-camera');
function aisathu () {
// Get the rotation element of a-camera
var rotation = camera.getAttribute ('rotation');
var Rot = rotation.y;
console.log (Rot);
// If camera turns 1-45 degrees
if (0<Rot<46) {console.log ("Good morning");}
// If the camera turns 4 to 90 degrees
else if (45<Rot<91) {console.log ( "Hello");}
// If camera turns 91-180 degrees
else if (91<Rot<181) {console.log ("Goodbye");}
else if (180<Rot<270) {console.log ("Good night");}
}
setInterval (aisathu, 1000);
</script>
</body>
</html>
I made rotation a global variable and tried conditional branching outside the function.
rotation.y was returned to aisathu function.
We use setInterval to always update the camera orientation.
-
Answer # 1
-
Answer # 2
I want to know what the behavior of the variable Rot looks like in console.log
I think that the angle of the camera is substituted for the variable Rot and it is displayed, but there is no possibility that the output specification on the camera side will output only once when the angle changes or such specification ?As a possibility, as I pointed out by kei344, I wonder if the writing of if is causing problems ...
What happens if you try the following?if (Rot>0&&Rot<46) {console.log ("Good morning");} // If the camera turns 4 to 90 degrees else if (Rot<91) {console.log ( "Hello");} // If camera turns 91-180 degrees else if (Rot<181) {console.log ("Goodbye");} else if (Rot<270) {console.log ("Good night");}
Related articles
- javascript - i want to write a code that is displayed while the characters change
- javascript - ui change when full screen is displayed with video tag
- javascript - the entered characters are not displayed js
- javascript - i want to eliminate the full calender not being displayed when deploying on aws
- javascript - how to make an array by separating with specified characters
- javascript - when i display the value entered in the form, it is displayed as undefined
- html - i don't know how to change the layout by putting characters in the image
- [unity] characters are not displayed even though it is hit
- javascript - i want to change the process using check in jquery
- javascript - i want to change the display range of the array
- javascript is not displayed on html
- javascript - no screen is displayed
- javascript - when posting using actioncable, the characters "undefined" will be displayed on the other party's screen
- i want to display characters in javascript p tag
- javascript - js error is displayed
- javascript - change text with vuejs v-for, @click
- javascript - li is not displayed todo list
- [javascript] an error is displayed on the console when writing with an immediate function
- javascript - i want to conditional branch html tag elements in react, jsx
- javascript - i want to change the display by selecting the radio button
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- python - you may need to restart the kernel to use updated packages error
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- python 3x - typeerror: 'method' object is not subscriptable
- javascript - how to check if an element exists in puppeteer
- xcode - pod install [!] no `podfile 'found in the project directory
- i want to call a child component method from a parent in vuejs
- vuejs - [vuetify] unable to locate target [data-app] i want to unit test to avoid warning
Rewrite
0instead of
0.