129 lines
No EOL
4.5 KiB
JavaScript
129 lines
No EOL
4.5 KiB
JavaScript
/* global randInt b:true*/
|
|
/* global randFloat b:true*/
|
|
Script.include("/~/system/libraries/utils.js");
|
|
(function () {
|
|
var DEBUG = false;
|
|
|
|
// var BASE_HEIGHT = 1.911; // Hips to foot distance = 0.82
|
|
var BASE_CHECK_DISTANCE = 0.43;
|
|
var BASE_RESET_DISTANCE = 0.155;
|
|
var BASE_SHIFT = 0.0;
|
|
|
|
|
|
var soundFileName = 'sounds/shoestep';
|
|
var soundFileTypes = ['a', 'b'];
|
|
var numberOfSounds = 2;
|
|
var soundPitchWobble = 0.5;
|
|
var volumeBase = 0.01;
|
|
var volumeWobble = 0.0401;
|
|
var feetBones = ['RightFoot', 'LeftFoot'];
|
|
|
|
|
|
var sndHooves = [];
|
|
var feetBonesDownStatus = [];
|
|
var soundTypePos = 0;
|
|
|
|
function initialize() {
|
|
loadSounds();
|
|
BASE_CHECK_DISTANCE += BASE_SHIFT;
|
|
BASE_RESET_DISTANCE += BASE_SHIFT;
|
|
|
|
for (var iTemp = 0; iTemp < feetBones.length; ++iTemp) {
|
|
feetBonesDownStatus[iTemp] = true;
|
|
}
|
|
Script.update.connect(eventTimer);
|
|
|
|
print("Therion Hoof Script Started...");
|
|
}
|
|
|
|
function loadSounds() {
|
|
var filePath; var soundHandle;
|
|
for (var iTemp = 1; iTemp < numberOfSounds + 1; ++iTemp) {
|
|
for (var iSoundType = 0; iSoundType < soundFileTypes.length; ++iSoundType) {
|
|
filePath = Script.resolvePath(soundFileName + "_" + soundFileTypes[iSoundType] + "_" + iTemp + ".wav");
|
|
// print("Loading "+filePath);
|
|
soundHandle = SoundCache.getSound(filePath);
|
|
sndHooves.push(soundHandle);
|
|
}
|
|
}
|
|
}
|
|
|
|
function checkFeet() {
|
|
var results = [];
|
|
var groundPosition = MyAvatar.getWorldFeetPosition();
|
|
|
|
if (DEBUG) {
|
|
DebugDraw.addMarker("hoofDbg_Ground",
|
|
{ x: 0, y: 0, z: 0, w: 1 },
|
|
MyAvatar.getWorldFeetPosition(),
|
|
{ x: 0, y: 1, z: 0, w: 1 });
|
|
}
|
|
|
|
var footPosition, footDistanceFromGround, footDownResult, footResetResult;
|
|
|
|
for (var iTemp = 0; iTemp < feetBones.length; ++iTemp) {
|
|
footPosition = MyAvatar.getJointPosition(feetBones[iTemp]);
|
|
footDistanceFromGround = footPosition.y - groundPosition.y;
|
|
|
|
results[iTemp] = 0;
|
|
// Are we down?
|
|
footResetResult = footDistanceFromGround > BASE_RESET_DISTANCE;
|
|
footDownResult = footDistanceFromGround < BASE_CHECK_DISTANCE;
|
|
|
|
if (footResetResult) {
|
|
results[iTemp] = 1;
|
|
} else if (footDownResult) {
|
|
results[iTemp] = 2;
|
|
}
|
|
}
|
|
|
|
return results;
|
|
}
|
|
|
|
function eventTimer(delta) {
|
|
var results = checkFeet();
|
|
var footPosition, footRotation;
|
|
for (var iTemp = 0; iTemp < feetBones.length; ++iTemp) {
|
|
footPosition = MyAvatar.getJointPosition(feetBones[iTemp]);
|
|
// footPosition = Vec3.sum(footPosition,{x:5,y:0,z:0});
|
|
if (!feetBonesDownStatus[iTemp] && results[iTemp] === 2) {
|
|
// Play the sound
|
|
Audio.playSound(sndHooves[(randInt(0, 2) * numberOfSounds) + soundTypePos], {
|
|
position: footPosition,
|
|
volume: volumeBase + randFloat(0, volumeWobble),
|
|
pitch: 4.0 + randFloat(1, soundPitchWobble)
|
|
});/**/
|
|
++soundTypePos;
|
|
if (soundTypePos === soundFileTypes.length) {
|
|
soundTypePos = 0;
|
|
}
|
|
|
|
if (DEBUG) {
|
|
DebugDraw.addMarker("hoofSnd",
|
|
{ x: 0, y: 0, z: 0, w: 1 },
|
|
footPosition,
|
|
{ x: 0, y: 2, z: 2, w: 1 });
|
|
}
|
|
// print("Stepped");
|
|
feetBonesDownStatus[iTemp] = true;
|
|
} else if (feetBonesDownStatus[iTemp] && results[iTemp] === 1) {
|
|
// print("Reset");
|
|
feetBonesDownStatus[iTemp] = false;
|
|
}
|
|
if (DEBUG) {
|
|
DebugDraw.addMarker("hoofDbg_" + feetBones[iTemp],
|
|
{ x: 0, y: 0, z: 0, w: 1 },
|
|
MyAvatar.getJointPosition(feetBones[iTemp]),
|
|
{ x: feetBonesDownStatus[iTemp], y: 0, z: !feetBonesDownStatus[iTemp], w: 1 });
|
|
}
|
|
}
|
|
}
|
|
|
|
initialize();
|
|
Script.scriptEnding.connect(function () {
|
|
Script.update.disconnect(eventTimer);
|
|
|
|
// Entities.deleteEntity(leftFootEntity);
|
|
// Entities.deleteEntity(rightFootEntity);
|
|
});
|
|
}()); |