SHARE
TWEET

Seek

Intreipd Aug 12th, 2017 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void BSeek::doActions(float deltaTime) {
  2.     if (m_parentObject != nullptr) {
  3.         glm::vec2 desired_velocity = m_targetPos - m_parentObject->getPos();
  4.         float last_dist_to_target = glm::length(m_targetPos - m_lastPos);
  5.         float dist_to_target = glm::length(desired_velocity);
  6.  
  7.         if (m_onInnerRadiusEnter && last_dist_to_target > m_innerRadius && dist_to_target <= m_innerRadius)
  8.             // If we have just entered the destination zone
  9.             m_onInnerRadiusEnter();
  10.         if (m_onInnerRadiusExit && last_dist_to_target <= m_innerRadius && dist_to_target > m_innerRadius)
  11.             // If we have just left the destination zone
  12.             m_onInnerRadiusExit();
  13.         if (m_onOuterRadiusEnter && last_dist_to_target > m_outerRadius && dist_to_target <= m_outerRadius)
  14.             // If we have just entered the agro zone
  15.                 m_onOuterRadiusEnter();
  16.         if (m_onOuterRadiusExit && last_dist_to_target <= m_outerRadius && dist_to_target > m_outerRadius)
  17.             // If we have just left the agro zone
  18.             m_onOuterRadiusExit();
  19.  
  20.  
  21.         if (dist_to_target <= m_outerRadius)
  22.             // Perform arrival behaviour
  23.             desired_velocity = glm::normalize(desired_velocity) * (dist_to_target / m_outerRadius) * m_strength;
  24.         else {
  25.             desired_velocity = glm::normalize(desired_velocity) * m_strength;
  26.         }
  27.  
  28.        
  29.         m_parentObject->applyForce(desired_velocity * getForceScale());
  30.  
  31.  
  32.         m_lastPos = m_parentObject->getPos();
  33.     }
  34. }
RAW Paste Data
Top