i have this sprite
as you can see, its a nob and I am turning it and logging its getEulerAngles and I want to change the audio when the angle is between 90 and 120 and then change the audio when the angle is between 120 and 180 and so on, I don’t know how to do that, this is my try so far:
update = function (dt) {
console.warn(this.nob.getEulerAngles().z);
if (this.app.keyboard.isPressed(pc.KEY_LEFT)) {
this.nob.rotateLocal(0, 0, 2);
}
if (this.app.keyboard.isPressed(pc.KEY_RIGHT)) {
this.nob.rotateLocal(0, 0, -2);
}
if(Math.floor(this.nob.getEulerAngles().z) > 90){
this.entity.sound.play('1');
}
};
its like a radio nob, where you change stations, I basically want to do that
FOUND IT:
// update code called every frame
Radiojammer.prototype.update = function(dt) {
console.warn(this.nob.getEulerAngles().z);
if (this.app.keyboard.isPressed(pc.KEY_LEFT)) {
//this.nob.setLocalRotation( this.nob.getLocalRotation().x + 1,this.nob.getLocalRotation().y,this.nob.getLocalRotation().z);
this.nob.rotateLocal(0, 0, 2);
}
if (this.app.keyboard.isPressed(pc.KEY_RIGHT)) {
//this.nob.setLocalRotation( this.nob.getLocalRotation().x + 1,this.nob.getLocalRotation().y,this.nob.getLocalRotation().z);
this.nob.rotateLocal(0, 0, -2);
}
if(Math.floor(this.nob.getEulerAngles().z) > 90 && Math.floor(this.nob.getEulerAngles().z) < 170){
this.playSound("1");
}
else if(Math.floor(this.nob.getEulerAngles().z) < 90 && Math.floor(this.nob.getEulerAngles().z) > 0){
this.playSound("2");
}
};
Radiojammer.prototype.playSound = function(soundToPlay) {
if(soundToPlay === this.currently_playing_sound){}
else
{
this.entity.sound.stop(this.currently_playing_sound);
this.entity.sound.play(soundToPlay);
this.currently_playing_sound = soundToPlay;}
};
1 Like