overte-AleziaKurdis/scripts/system/controllers/mouseLook.js
rampa3 5f34d04596 Added initial mouse look script
Added initial WIP implementation of mouse look script.
2023-08-22 19:05:05 +02:00

85 lines
No EOL
2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
mouseLook.js mouse look switching script
by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon)
*/
(function() { // BEGIN LOCAL_SCOPE
var oldMode;
var mouseLookEnabled = false;
mouseLookOn();
Controller.keyPressEvent.connect(function(event) {
if (event.text === 'm') {
if (mouseLookEnabled) {
if (!Camera.getCaptureMouse()){
Window.displayAnnouncement("Mouse look: ON");
mouseLookOn();
} else {
Window.displayAnnouncement("Mouse look: TEMPORARILY OFF");
mouseLookOff();
}
}
}
if (event.text === 'M') {
if (!mouseLookEnabled){
Window.displayAnnouncement("Mouse look: ENABLED")
mouseLookEnabled = true;
mouseLookOn();
} else {
Window.displayAnnouncement("Mouse look: DISABLED")
mouseLookEnabled = false;
mouseLookOff();
}
}
});
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
tablet.tabletShownChanged.connect(function () {
if (!tablet.toolbarMode) {
if (tablet.tabletShown) {
Window.displayAnnouncement("Tablet is up mouse look temporarily off.");
mouseLookOff();
} else if (!tablet.tabletShown) {
Window.displayAnnouncement("Tablet hidden mouse look on.");
mouseLookOn();
}
}
});
MyAvatar.wentAway.connect(function () {
Window.displayAnnouncement("Away state ON mouse look temporarily off.")
mouseLookOff()
});
MyAvatar.wentActive.connect(function () {
Window.displayAnnouncement("Away state OFF mouse look on.");
mouseLookOn();
});
function mouseLookOn() {
oldMode = Camera.mode;
Camera.mode = "first person";
Camera.captureMouse = true;
}
function mouseLookOff() {
Camera.captureMouse = false;
Camera.mode = oldMode;
}
function onCameraModeUpdated(newMode) {
if (Camera.getCaptureMouse()){
Camera.captureMouse = false;
}
}
Camera.modeUpdated.connect(onCameraModeUpdated);
Script.scriptEnding.connect(function() {
Camera.captureMouse = false;
});
}()); // END LOCAL_SCOPE