mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 04:03:35 +02:00
Switched to Halo gun in gun.js, work in progress on hydraMove to add flying
This commit is contained in:
parent
20749b48da
commit
394985ef45
2 changed files with 56 additions and 47 deletions
|
@ -39,7 +39,7 @@ var impactSound = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-pub
|
||||||
var targetHitSound = new Sound("http://highfidelity-public.s3-us-west-1.amazonaws.com/sounds/Space%20Invaders/hit.raw");
|
var targetHitSound = new Sound("http://highfidelity-public.s3-us-west-1.amazonaws.com/sounds/Space%20Invaders/hit.raw");
|
||||||
var targetLaunchSound = new Sound("http://highfidelity-public.s3-us-west-1.amazonaws.com/sounds/Space%20Invaders/shoot.raw");
|
var targetLaunchSound = new Sound("http://highfidelity-public.s3-us-west-1.amazonaws.com/sounds/Space%20Invaders/shoot.raw");
|
||||||
|
|
||||||
var gunModel = "http://highfidelity-public.s3-us-west-1.amazonaws.com/models/attachments/Raygun2.fst";
|
var gunModel = "http://public.highfidelity.io/models/attachments/HaloGun.fst";
|
||||||
|
|
||||||
var audioOptions = new AudioInjectionOptions();
|
var audioOptions = new AudioInjectionOptions();
|
||||||
audioOptions.volume = 0.9;
|
audioOptions.volume = 0.9;
|
||||||
|
@ -199,7 +199,7 @@ function playLoadSound() {
|
||||||
Audio.playSound(loadSound, audioOptions);
|
Audio.playSound(loadSound, audioOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
MyAvatar.attach(gunModel, "RightHand", {x: -0.02, y: -.14, z: 0.07}, Quat.fromPitchYawRollDegrees(-70, -151, 72), 0.20);
|
//MyAvatar.attach(gunModel, "RightHand", {x: -0.02, y: -.14, z: 0.07}, Quat.fromPitchYawRollDegrees(-70, -151, 72), 0.20);
|
||||||
MyAvatar.attach(gunModel, "LeftHand", {x: -0.02, y: -.14, z: 0.07}, Quat.fromPitchYawRollDegrees(-70, -151, 72), 0.20);
|
MyAvatar.attach(gunModel, "LeftHand", {x: -0.02, y: -.14, z: 0.07}, Quat.fromPitchYawRollDegrees(-70, -151, 72), 0.20);
|
||||||
|
|
||||||
// Give a bit of time to load before playing sound
|
// Give a bit of time to load before playing sound
|
||||||
|
@ -320,7 +320,6 @@ function scriptEnding() {
|
||||||
Overlays.deleteOverlay(reticle);
|
Overlays.deleteOverlay(reticle);
|
||||||
Overlays.deleteOverlay(text);
|
Overlays.deleteOverlay(text);
|
||||||
MyAvatar.detachOne(gunModel);
|
MyAvatar.detachOne(gunModel);
|
||||||
MyAvatar.detachOne(gunModel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Particles.particleCollisionWithVoxel.connect(particleCollisionWithVoxel);
|
Particles.particleCollisionWithVoxel.connect(particleCollisionWithVoxel);
|
||||||
|
|
|
@ -50,6 +50,13 @@ var LEFT_BUTTON_4 = 4;
|
||||||
var RIGHT_PALM = 2;
|
var RIGHT_PALM = 2;
|
||||||
var RIGHT_BUTTON_4 = 10;
|
var RIGHT_BUTTON_4 = 10;
|
||||||
|
|
||||||
|
|
||||||
|
function printVector(text, v, decimals) {
|
||||||
|
print(text + " " + v.x.toFixed(decimals) + ", " + v.y.toFixed(decimals) + ", " + v.z.toFixed(decimals));
|
||||||
|
}
|
||||||
|
|
||||||
|
var debug = true;
|
||||||
|
|
||||||
// Used by handleGrabBehavior() for managing the grab position changes
|
// Used by handleGrabBehavior() for managing the grab position changes
|
||||||
function getAndResetGrabDelta() {
|
function getAndResetGrabDelta() {
|
||||||
var HAND_GRAB_SCALE_DISTANCE = 2.0;
|
var HAND_GRAB_SCALE_DISTANCE = 2.0;
|
||||||
|
@ -60,24 +67,12 @@ function getAndResetGrabDelta() {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used by handleGrabBehavior() for managing the grab velocity feature
|
function getGrabRotation() {
|
||||||
function getAndResetGrabDeltaVelocity() {
|
|
||||||
var HAND_GRAB_SCALE_VELOCITY = 50.0;
|
|
||||||
var delta = Vec3.multiply(grabDeltaVelocity, (MyAvatar.scale * HAND_GRAB_SCALE_VELOCITY));
|
|
||||||
grabDeltaVelocity = { x: 0, y: 0, z: 0};
|
|
||||||
var avatarRotation = MyAvatar.orientation;
|
|
||||||
var result = Quat.multiply(avatarRotation, Vec3.multiply(delta, -1));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Used by handleGrabBehavior() for managing the grab rotation feature
|
|
||||||
function getAndResetGrabRotation() {
|
|
||||||
var quatDiff = Quat.multiply(grabCurrentRotation, Quat.inverse(grabStartRotation));
|
var quatDiff = Quat.multiply(grabCurrentRotation, Quat.inverse(grabStartRotation));
|
||||||
grabStartRotation = grabCurrentRotation;
|
|
||||||
return quatDiff;
|
return quatDiff;
|
||||||
}
|
}
|
||||||
|
|
||||||
// handles all the grab related behavior: position (crawl), velocity (flick), and rotate (twist)
|
// When move button is pressed, process results
|
||||||
function handleGrabBehavior(deltaTime) {
|
function handleGrabBehavior(deltaTime) {
|
||||||
// check for and handle grab behaviors
|
// check for and handle grab behaviors
|
||||||
grabbingWithRightHand = Controller.isButtonPressed(RIGHT_BUTTON_4);
|
grabbingWithRightHand = Controller.isButtonPressed(RIGHT_BUTTON_4);
|
||||||
|
@ -88,9 +83,12 @@ function handleGrabBehavior(deltaTime) {
|
||||||
if (grabbingWithRightHand && !wasGrabbingWithRightHand) {
|
if (grabbingWithRightHand && !wasGrabbingWithRightHand) {
|
||||||
// Just starting grab, capture starting rotation
|
// Just starting grab, capture starting rotation
|
||||||
grabStartRotation = Controller.getSpatialControlRawRotation(RIGHT_PALM);
|
grabStartRotation = Controller.getSpatialControlRawRotation(RIGHT_PALM);
|
||||||
|
grabStartPosition = Controller.getSpatialControlPosition(RIGHT_PALM);
|
||||||
|
if (debug) printVector("start position", grabStartPosition, 3);
|
||||||
}
|
}
|
||||||
if (grabbingWithRightHand) {
|
if (grabbingWithRightHand) {
|
||||||
grabDelta = Vec3.sum(grabDelta, Vec3.multiply(Controller.getSpatialControlVelocity(RIGHT_PALM), deltaTime));
|
//grabDelta = Vec3.sum(grabDelta, Vec3.multiply(Controller.getSpatialControlVelocity(RIGHT_PALM), deltaTime));
|
||||||
|
grabDelta = Vec3.subtract(Controller.getSpatialControlPosition(RIGHT_PALM), grabStartPosition);
|
||||||
grabCurrentRotation = Controller.getSpatialControlRawRotation(RIGHT_PALM);
|
grabCurrentRotation = Controller.getSpatialControlRawRotation(RIGHT_PALM);
|
||||||
}
|
}
|
||||||
if (!grabbingWithRightHand && wasGrabbingWithRightHand) {
|
if (!grabbingWithRightHand && wasGrabbingWithRightHand) {
|
||||||
|
@ -102,10 +100,13 @@ function handleGrabBehavior(deltaTime) {
|
||||||
if (grabbingWithLeftHand && !wasGrabbingWithLeftHand) {
|
if (grabbingWithLeftHand && !wasGrabbingWithLeftHand) {
|
||||||
// Just starting grab, capture starting rotation
|
// Just starting grab, capture starting rotation
|
||||||
grabStartRotation = Controller.getSpatialControlRawRotation(LEFT_PALM);
|
grabStartRotation = Controller.getSpatialControlRawRotation(LEFT_PALM);
|
||||||
|
grabStartPosition = Controller.getSpatialControlPosition(LEFT_PALM);
|
||||||
|
if (debug) printVector("start position", grabStartPosition, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (grabbingWithLeftHand) {
|
if (grabbingWithLeftHand) {
|
||||||
grabDelta = Vec3.sum(grabDelta, Vec3.multiply(Controller.getSpatialControlVelocity(LEFT_PALM), deltaTime));
|
//grabDelta = Vec3.sum(grabDelta, Vec3.multiply(Controller.getSpatialControlVelocity(LEFT_PALM), deltaTime));
|
||||||
|
grabDelta = Vec3.subtract(Controller.getSpatialControlPosition(LEFT_PALM), grabStartPosition);
|
||||||
grabCurrentRotation = Controller.getSpatialControlRawRotation(LEFT_PALM);
|
grabCurrentRotation = Controller.getSpatialControlRawRotation(LEFT_PALM);
|
||||||
}
|
}
|
||||||
if (!grabbingWithLeftHand && wasGrabbingWithLeftHand) {
|
if (!grabbingWithLeftHand && wasGrabbingWithLeftHand) {
|
||||||
|
@ -119,44 +120,53 @@ function handleGrabBehavior(deltaTime) {
|
||||||
|
|
||||||
if (grabbing) {
|
if (grabbing) {
|
||||||
|
|
||||||
// move position
|
var headOrientation = MyAvatar.headOrientation;
|
||||||
var moveFromGrab = getAndResetGrabDelta();
|
var front = Quat.getFront(headOrientation);
|
||||||
if (Vec3.length(moveFromGrab) > EPSILON) {
|
var right = Quat.getRight(headOrientation);
|
||||||
MyAvatar.position = Vec3.sum(MyAvatar.position, moveFromGrab);
|
var up = Quat.getUp(headOrientation);
|
||||||
velocity = { x: 0, y: 0, z: 0};
|
|
||||||
}
|
|
||||||
|
|
||||||
// add some rotation...
|
|
||||||
var deltaRotation = getAndResetGrabRotation();
|
|
||||||
var GRAB_CONTROLLER_TURN_SCALING = 0.5;
|
|
||||||
var euler = Vec3.multiply(Quat.safeEulerAngles(deltaRotation), GRAB_CONTROLLER_TURN_SCALING);
|
|
||||||
|
|
||||||
// Adjust body yaw by yaw from controller
|
//grabDelta = Quat.multiply(headOrientation, grabDelta);
|
||||||
var orientation = Quat.multiply(Quat.angleAxis(-euler.y, {x:0, y: 1, z:0}), MyAvatar.orientation);
|
//grabDelta = Quat.multiply(Camera.getOrientation(), grabDelta);
|
||||||
|
grabDelta = Vec3.multiplyQbyV(MyAvatar.orientation, Vec3.multiply(grabDelta, -1));
|
||||||
|
|
||||||
|
if (debug) {
|
||||||
|
printVector("grabDelta: ", grabDelta, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
var THRUST_GRAB_SCALING = 0.0;
|
||||||
|
|
||||||
|
var thrustFront = Vec3.multiply(front, MyAvatar.scale * grabDelta.z * THRUST_GRAB_SCALING * deltaTime);
|
||||||
|
MyAvatar.addThrust(thrustFront);
|
||||||
|
var thrustRight = Vec3.multiply(right, MyAvatar.scale * grabDelta.x * THRUST_GRAB_SCALING * deltaTime);
|
||||||
|
MyAvatar.addThrust(thrustRight);
|
||||||
|
var thrustUp = Vec3.multiply(up, MyAvatar.scale * grabDelta.y * THRUST_GRAB_SCALING * deltaTime);
|
||||||
|
MyAvatar.addThrust(thrustUp);
|
||||||
|
|
||||||
|
|
||||||
|
// add some rotation...
|
||||||
|
var deltaRotation = getGrabRotation();
|
||||||
|
var GRAB_CONTROLLER_PITCH_SCALING = 2.5;
|
||||||
|
var GRAB_CONTROLLER_YAW_SCALING = 2.5;
|
||||||
|
var GRAB_CONTROLLER_ROLL_SCALING = 2.5;
|
||||||
|
var euler = Quat.safeEulerAngles(deltaRotation);
|
||||||
|
|
||||||
|
// Adjust body yaw by roll from controller
|
||||||
|
var orientation = Quat.multiply(Quat.angleAxis(((euler.y * GRAB_CONTROLLER_YAW_SCALING) +
|
||||||
|
(euler.z * GRAB_CONTROLLER_ROLL_SCALING)) * deltaTime, {x:0, y: 1, z:0}), MyAvatar.orientation);
|
||||||
MyAvatar.orientation = orientation;
|
MyAvatar.orientation = orientation;
|
||||||
|
|
||||||
// Adjust head pitch from controller
|
// Adjust head pitch from controller
|
||||||
MyAvatar.headPitch = MyAvatar.headPitch - euler.x;
|
MyAvatar.headPitch = MyAvatar.headPitch + (euler.x * GRAB_CONTROLLER_PITCH_SCALING * deltaTime);
|
||||||
|
|
||||||
|
// Add some camera roll proportional to the rate of turn (so it feels like an airplane or roller coaster)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// add some velocity...
|
|
||||||
if (stoppedGrabbing) {
|
|
||||||
velocity = Vec3.sum(velocity, getAndResetGrabDeltaVelocity());
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle residual velocity
|
|
||||||
if(Vec3.length(velocity) > EPSILON) {
|
|
||||||
MyAvatar.position = Vec3.sum(MyAvatar.position, Vec3.multiply(velocity, deltaTime));
|
|
||||||
// damp velocity
|
|
||||||
velocity = Vec3.multiply(velocity, damping);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
wasGrabbingWithRightHand = grabbingWithRightHand;
|
wasGrabbingWithRightHand = grabbingWithRightHand;
|
||||||
wasGrabbingWithLeftHand = grabbingWithLeftHand;
|
wasGrabbingWithLeftHand = grabbingWithLeftHand;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main update function that handles flying and grabbing behaviort
|
// Update for joysticks and move button
|
||||||
function flyWithHydra(deltaTime) {
|
function flyWithHydra(deltaTime) {
|
||||||
var thrustJoystickPosition = Controller.getJoystickPosition(THRUST_CONTROLLER);
|
var thrustJoystickPosition = Controller.getJoystickPosition(THRUST_CONTROLLER);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue