mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 02:56:50 +02:00
Fix MyAvatar's velocity change
This commit is contained in:
parent
07adef9465
commit
bc6544a3c5
3 changed files with 18 additions and 1 deletions
|
@ -311,7 +311,9 @@ void AvatarManager::handleCollisionEvents(const CollisionEvents& collisionEvents
|
||||||
MyAvatar* myAvatar = getMyAvatar();
|
MyAvatar* myAvatar = getMyAvatar();
|
||||||
auto collisionSound = myAvatar->getCollisionSound();
|
auto collisionSound = myAvatar->getCollisionSound();
|
||||||
if (collisionSound) {
|
if (collisionSound) {
|
||||||
const float velocityChange = glm::length(collision.velocityChange);
|
const auto characterController = myAvatar->getCharacterController();
|
||||||
|
const float avatarVelocityChange = (characterController ? glm::length(characterController->getVelocityChange()) : 0.0f);
|
||||||
|
const float velocityChange = glm::length(collision.velocityChange) + avatarVelocityChange;
|
||||||
const float MIN_AVATAR_COLLISION_ACCELERATION = 0.01f;
|
const float MIN_AVATAR_COLLISION_ACCELERATION = 0.01f;
|
||||||
const bool isSound = (collision.type == CONTACT_EVENT_TYPE_START) && (velocityChange > MIN_AVATAR_COLLISION_ACCELERATION);
|
const bool isSound = (collision.type == CONTACT_EVENT_TYPE_START) && (velocityChange > MIN_AVATAR_COLLISION_ACCELERATION);
|
||||||
|
|
||||||
|
|
|
@ -430,6 +430,14 @@ glm::vec3 CharacterController::getLinearVelocity() const {
|
||||||
return velocity;
|
return velocity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glm::vec3 CharacterController::getVelocityChange() const {
|
||||||
|
glm::vec3 velocity(0.0f);
|
||||||
|
if (_rigidBody) {
|
||||||
|
velocity = bulletToGLM(_rigidBody->getLinearVelocity());
|
||||||
|
}
|
||||||
|
return velocity;
|
||||||
|
}
|
||||||
|
|
||||||
void CharacterController::preSimulation() {
|
void CharacterController::preSimulation() {
|
||||||
if (_enabled && _dynamicsWorld) {
|
if (_enabled && _dynamicsWorld) {
|
||||||
quint64 now = usecTimestampNow();
|
quint64 now = usecTimestampNow();
|
||||||
|
@ -437,6 +445,7 @@ void CharacterController::preSimulation() {
|
||||||
// slam body to where it is supposed to be
|
// slam body to where it is supposed to be
|
||||||
_rigidBody->setWorldTransform(_characterBodyTransform);
|
_rigidBody->setWorldTransform(_characterBodyTransform);
|
||||||
btVector3 velocity = _rigidBody->getLinearVelocity();
|
btVector3 velocity = _rigidBody->getLinearVelocity();
|
||||||
|
_preSimulationVelocity = velocity;
|
||||||
|
|
||||||
btVector3 actualVertVelocity = velocity.dot(_currentUp) * _currentUp;
|
btVector3 actualVertVelocity = velocity.dot(_currentUp) * _currentUp;
|
||||||
btVector3 actualHorizVelocity = velocity - actualVertVelocity;
|
btVector3 actualHorizVelocity = velocity - actualVertVelocity;
|
||||||
|
@ -531,6 +540,9 @@ void CharacterController::preSimulation() {
|
||||||
|
|
||||||
void CharacterController::postSimulation() {
|
void CharacterController::postSimulation() {
|
||||||
// postSimulation() exists for symmetry and just in case we need to do something here later
|
// postSimulation() exists for symmetry and just in case we need to do something here later
|
||||||
|
|
||||||
|
btVector3 velocity = _rigidBody->getLinearVelocity();
|
||||||
|
_velocityChange = velocity - _preSimulationVelocity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -77,6 +77,7 @@ public:
|
||||||
glm::vec3 getFollowVelocity() const;
|
glm::vec3 getFollowVelocity() const;
|
||||||
|
|
||||||
glm::vec3 getLinearVelocity() const;
|
glm::vec3 getLinearVelocity() const;
|
||||||
|
glm::vec3 getVelocityChange() const;
|
||||||
|
|
||||||
float getCapsuleRadius() const { return _radius; }
|
float getCapsuleRadius() const { return _radius; }
|
||||||
float getCapsuleHalfHeight() const { return _halfHeight; }
|
float getCapsuleHalfHeight() const { return _halfHeight; }
|
||||||
|
@ -112,6 +113,8 @@ protected:
|
||||||
btVector3 _currentUp;
|
btVector3 _currentUp;
|
||||||
btVector3 _targetVelocity;
|
btVector3 _targetVelocity;
|
||||||
btVector3 _parentVelocity;
|
btVector3 _parentVelocity;
|
||||||
|
btVector3 _preSimulationVelocity;
|
||||||
|
btVector3 _velocityChange;
|
||||||
btTransform _followDesiredBodyTransform;
|
btTransform _followDesiredBodyTransform;
|
||||||
btScalar _followTimeRemaining;
|
btScalar _followTimeRemaining;
|
||||||
btTransform _characterBodyTransform;
|
btTransform _characterBodyTransform;
|
||||||
|
|
Loading…
Reference in a new issue