make avatar walk-speed adjustable from js. add a tablet button to control walking vs running

This commit is contained in:
Seth Alves 2018-01-08 15:27:41 -08:00
parent 1c94c9c11d
commit ad389e5072
3 changed files with 45 additions and 1 deletions

View file

@ -2100,7 +2100,7 @@ void MyAvatar::updateActionMotor(float deltaTime) {
_actionMotorVelocity = motorSpeed * direction; _actionMotorVelocity = motorSpeed * direction;
} else { } else {
// we're interacting with a floor --> simple horizontal speed and exponential decay // we're interacting with a floor --> simple horizontal speed and exponential decay
_actionMotorVelocity = getSensorToWorldScale() * DEFAULT_AVATAR_MAX_WALKING_SPEED * direction; _actionMotorVelocity = getSensorToWorldScale() * _walkSpeed.get() * direction;
} }
float boomChange = getDriveKey(ZOOM); float boomChange = getDriveKey(ZOOM);
@ -2692,6 +2692,14 @@ float MyAvatar::getUserEyeHeight() const {
return userHeight - userHeight * ratio; return userHeight - userHeight * ratio;
} }
float MyAvatar::getWalkSpeed() const {
return _walkSpeed.get();
}
void MyAvatar::setWalkSpeed(float value) {
_walkSpeed.set(value);
}
glm::vec3 MyAvatar::getPositionForAudio() { glm::vec3 MyAvatar::getPositionForAudio() {
switch (_audioListenerMode) { switch (_audioListenerMode) {
case AudioListenerMode::FROM_HEAD: case AudioListenerMode::FROM_HEAD:

View file

@ -163,6 +163,8 @@ class MyAvatar : public Avatar {
Q_PROPERTY(QUuid SELF_ID READ getSelfID CONSTANT) Q_PROPERTY(QUuid SELF_ID READ getSelfID CONSTANT)
Q_PROPERTY(float walkSpeed READ getWalkSpeed WRITE setWalkSpeed);
const QString DOMINANT_LEFT_HAND = "left"; const QString DOMINANT_LEFT_HAND = "left";
const QString DOMINANT_RIGHT_HAND = "right"; const QString DOMINANT_RIGHT_HAND = "right";
@ -557,6 +559,9 @@ public:
const QUuid& getSelfID() const { return AVATAR_SELF_ID; } const QUuid& getSelfID() const { return AVATAR_SELF_ID; }
void setWalkSpeed(float value);
float getWalkSpeed() const;
public slots: public slots:
void increaseSize(); void increaseSize();
void decreaseSize(); void decreaseSize();
@ -841,6 +846,9 @@ private:
// height of user in sensor space, when standing erect. // height of user in sensor space, when standing erect.
ThreadSafeValueCache<float> _userHeight { DEFAULT_AVATAR_HEIGHT }; ThreadSafeValueCache<float> _userHeight { DEFAULT_AVATAR_HEIGHT };
// max unscaled forward movement speed
ThreadSafeValueCache<float> _walkSpeed { DEFAULT_AVATAR_MAX_WALKING_SPEED };
}; };
QScriptValue audioListenModeToScriptValue(QScriptEngine* engine, const AudioListenerMode& audioListenerMode); QScriptValue audioListenModeToScriptValue(QScriptEngine* engine, const AudioListenerMode& audioListenerMode);

28
scripts/system/run.js Normal file
View file

@ -0,0 +1,28 @@
"use strict";
/* global Script, Tablet, MyAvatar */
(function() { // BEGIN LOCAL_SCOPE
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
var button = tablet.addButton({
icon: Script.resolvePath("run.svg"),
text: "Run",
sortOrder: 15
});
function onClicked() {
if (MyAvatar.walkSpeed < 4) {
MyAvatar.walkSpeed = 4.5;
} else {
MyAvatar.walkSpeed = 3.0;
}
}
function cleanup() {
button.clicked.disconnect(onClicked);
tablet.removeButton(button);
}
button.clicked.connect(onClicked);
})