Slow down when near other avatars - incremental commit

This commit is contained in:
Philip Rosedale 2013-05-01 20:55:40 -07:00
parent 08e1bfb712
commit 09a6a476d5

View file

@ -320,6 +320,8 @@ void Avatar::setMousePressed( bool d ) {
void Avatar::simulate(float deltaTime) { void Avatar::simulate(float deltaTime) {
float nearestAvatarDistance = 1000000.f;
// update balls // update balls
if (_balls) { _balls->simulate(deltaTime); } if (_balls) { _balls->simulate(deltaTime); }
@ -341,7 +343,7 @@ void Avatar::simulate(float deltaTime) {
if ( _isMine ) if ( _isMine )
{ {
float closestDistance = 10000.0f; float closestDistance = 10000.0f;
AgentList* agentList = AgentList::getInstance(); AgentList* agentList = AgentList::getInstance();
for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) {
if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) { if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) {
@ -355,6 +357,8 @@ void Avatar::simulate(float deltaTime) {
v -= otherAvatar->getBonePosition( AVATAR_BONE_RIGHT_HAND ); v -= otherAvatar->getBonePosition( AVATAR_BONE_RIGHT_HAND );
float distance = glm::length( v ); float distance = glm::length( v );
if ( distance < nearestAvatarDistance ) { nearestAvatarDistance = distance; }
if ( distance < _maxArmLength + _maxArmLength ) { if ( distance < _maxArmLength + _maxArmLength ) {
closestDistance = distance; closestDistance = distance;
@ -442,6 +446,11 @@ void Avatar::simulate(float deltaTime) {
// decay velocity // decay velocity
_velocity *= ( 1.0 - LIN_VEL_DECAY * deltaTime ); _velocity *= ( 1.0 - LIN_VEL_DECAY * deltaTime );
// If other avatars nearby, damp velocity much more!
if (_isMine && (nearestAvatarDistance < 3.f)) {
_velocity *= (1.0 - fmin(10.f * glm::length(_velocity) * deltaTime, 1.0));
}
// update head information // update head information
updateHead(deltaTime); updateHead(deltaTime);