mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 20:57:09 +02:00
Merge pull request #3901 from huffman/gamepad-multi-speed
Add multi-speed control to gamepad.js
This commit is contained in:
commit
b9ce5b0d0c
1 changed files with 9 additions and 2 deletions
|
@ -16,6 +16,8 @@ var AXIS_STRAFE = Joysticks.AXIS_LEFT_X;
|
|||
var AXIS_FORWARD = Joysticks.AXIS_LEFT_Y;
|
||||
var AXIS_ROTATE = Joysticks.AXIS_RIGHT_X;
|
||||
|
||||
var BUTTON_SPRINT = Joysticks.BUTTON_LEFT_STICK;
|
||||
|
||||
var BUTTON_TURN_AROUND = Joysticks.BUTTON_RIGHT_STICK;
|
||||
|
||||
var BUTTON_FLY_UP = Joysticks.BUTTON_RIGHT_SHOULDER;
|
||||
|
@ -31,7 +33,8 @@ var BUTTON_WARP_RIGHT = Joysticks.BUTTON_DPAD_RIGHT;
|
|||
var WARP_DISTANCE = 1;
|
||||
|
||||
// Walk speed in m/s
|
||||
var MOVE_SPEED = 2;
|
||||
var MOVE_SPEED = 0.5;
|
||||
var MOVE_SPRINT_SPEED = 2;
|
||||
|
||||
// Amount to rotate in radians
|
||||
var ROTATE_INCREMENT = Math.PI / 8;
|
||||
|
@ -49,6 +52,7 @@ var flyUpButtonState = false;
|
|||
// Current move direction, axis aligned - that is, looking down and moving forward
|
||||
// will not move you into the ground, but instead will keep you on the horizontal plane.
|
||||
var moveDirection = { x: 0, y: 0, z: 0 };
|
||||
var sprintButtonState = false;
|
||||
|
||||
var warpActive = false;
|
||||
var warpPosition = { x: 0, y: 0, z: 0 };
|
||||
|
@ -173,6 +177,8 @@ function reportButtonValue(button, newValue, oldValue) {
|
|||
MyAvatar.orientation = Quat.multiply(
|
||||
Quat.fromPitchYawRollRadians(0, Math.PI, 0), MyAvatar.orientation);
|
||||
}
|
||||
} else if (button == BUTTON_SPRINT) {
|
||||
sprintButtonState = newValue;
|
||||
} else if (newValue) {
|
||||
var direction = null;
|
||||
|
||||
|
@ -209,9 +215,10 @@ function update(dt) {
|
|||
var move = copyVec3(moveDirection);
|
||||
move.y = 0;
|
||||
if (Vec3.length(move) > 0) {
|
||||
speed = sprintButtonState ? MOVE_SPRINT_SPEED : MOVE_SPEED;
|
||||
velocity = Vec3.multiplyQbyV(Camera.getOrientation(), move);
|
||||
velocity.y = 0;
|
||||
velocity = Vec3.multiply(Vec3.normalize(velocity), MOVE_SPEED);
|
||||
velocity = Vec3.multiply(Vec3.normalize(velocity), speed);
|
||||
}
|
||||
|
||||
if (moveDirection.y != 0) {
|
||||
|
|
Loading…
Reference in a new issue